正则表达式 re.findall 用法

正则 re.findall  的简单用法(返回string中所有与pattern相匹配的全部字串,返回形式为数组)
语法:

1

findall(pattern, string, flags=0)

import rePython 正则表达式 re findall 方法能够以列表的形式返回能匹配的子串# print (help(re.findall))
# print (dir(re.findall))findall查找全部r标识代表后面是正则的语句

?

1

2

3

regular_v1 = re.findall(r"docs","https://docs.python.org/3/whatsnew/3.6.html")

print (regular_v1)

# ['docs']

符号^表示匹配以https开头的的字符串返回,

?

1

2

3

regular_v2 = re.findall(r"^https","https://docs.python.org/3/whatsnew/3.6.html")

print (regular_v2)

# ['https']

  

用$符号表示以html结尾的字符串返回,判断是否字符串结束的字符串

?

1

2

3

regular_v3 = re.findall(r"html$","https://docs.python.org/3/whatsnew/3.6.html")

print (regular_v3)

# ['html']

# [...]匹配括号中的其中一个字符

?

1

2

3

regular_v4 = re.findall(r"[t,w]h","https://docs.python.org/3/whatsnew/3.6.html")

print (regular_v4)

# ['th', 'wh']

“d”是正则语法规则用来匹配0到9之间的数返回列表

?

1

2

3

4

5

6

regular_v5 = re.findall(r"\d","https://docs.python.org/3/whatsnew/3.6.html")

regular_v6 = re.findall(r"\d\d\d","https://docs.python.org/3/whatsnew/3.6.html/1234")

print (regular_v5)

# ['3', '3', '6']

print (regular_v6)

# ['123']

小d表示取数字0-9,大D表示不要数字,也就是出了数字以外的内容返回

?

1

2

3

regular_v7 = re.findall(r"\D","https://docs.python.org/3/whatsnew/3.6.html")

print (regular_v7)

# ['h', 't', 't', 'p', 's', ':', '/', '/', 'd', 'o', 'c', 's', '.', 'p', 'y', 't', 'h', 'o', 'n', '.', 'o', 'r', 'g', '/', '/', 'w', 'h', 'a', 't', 's', 'n', 'e', 'w', '/', '.', '.', 'h', 't', 'm', 'l']

“w”在正则里面代表匹配从小写a到z,大写A到Z,数字0到9

?

1

2

3

regular_v8 = re.findall(r"\w","https://docs.python.org/3/whatsnew/3.6.html")

print (regular_v8)

#['h', 't', 't', 'p', 's', 'd', 'o', 'c', 's', 'p', 'y', 't', 'h', 'o', 'n', 'o', 'r', 'g', '3', 'w', 'h', 'a', 't', 's', 'n', 'e', 'w', '3', '6', 'h', 't', 'm', 'l']

“W”在正则里面代表匹配除了字母与数字以外的特殊符号

?

1

2

3

regular_v9 = re.findall(r"\W","https://docs.python.org/3/whatsnew/3.6.html")

print (regular_v9)

# [':', '/', '/', '.', '.', '/', '/', '/', '.', '.']

正则表达式 re.findall 用法,包含正则规则讲解相关推荐

  1. python正则findall函数的用法_python中正则表达式 re.findall 用法

    python中正则表达式 re.findall 用法 Python 正则表达式 正则表达式是一个特殊的字符序列,它能帮助你方便的检查一个字符串是否与某种模式匹配. Python 自1.5版本起增加了r ...

  2. python正则表达式findall_正则表达式 re.findall 用法

    正则 re.findall 的简单用法(返回string中所有与pattern相匹配的全部字串,返回形式为数组) 语法: findall(pattern, string, flags=0) impor ...

  3. 正则表达式 re.findall 用法

    正则 re.findall 的简单用法(返回string中所有与pattern相匹配的全部字串,返回形式为数组) 语法: findall(pattern, string, flags=0) impor ...

  4. python findall用法_Python 正则表达re模块之findall()详解

    目录 一.re.findall函数介绍 二.代码如下 三.re.findall中正则表达式(.*?) 四.re.findall中参数re.S的意义 一.re.findall函数介绍 它在re.py中有 ...

  5. java 正则 不包含_java使用正则表达式匹配不包含某个规则的字符串

    测试数据: 例如上面这几条简单的日志条目,我们想实现两个目标: 1.把8号的数据过滤掉: 2.把那些不包含robots.txt字符串的条目给找出来(只要Url中包含robots.txt的都给过滤掉). ...

  6. mysql正则替换_MySQL中使用replace、regexp进行正则表达式替换的用法分析

    本文实例讲述了MySQL中使用replace.regexp进行正则表达式替换的用法.分享给大家供大家参考,具体如下: 今天一个朋友问我,如果将数据库中查到的类似于"./uploads/110 ...

  7. Python中正则表达式findall用法

    一:前言 在写着自动化测试的脚本时,重新复习了一下正则表达式findall()方法.为了深化印象,输出点东西,就来写个通过正则表达式爬取菜鸟教程标题的小案例. 参考教程:菜鸟教程之Python正则表达 ...

  8. 判断输入的正则表达式是否符合正则规则

    判断输入的正则表达式是否符合正则规则 方法一: const validateRegular=(rulevalue,callback)=>{ if (value !== undefined &am ...

  9. mysql 正则替换 换行,MySQL中使用replace、regexp进行正则表达式替换的用法分析

    本文实例讲述了MySQL中使用replace.regexp进行正则表达式替换的用法.,具体如下: 今天一个朋友问我,如果将数据库中查到的类似于"./uploads/110100_cityHo ...

最新文章

  1. 服务端发post请求产生的编码问题
  2. 教程:给初学的几个小例子(待补充)
  3. 23种设计模式C++源码与UML实现--适配器模式
  4. 全民直播,半年“用云量”暴涨五倍
  5. 【总议程】2021全球分布式云大会·上海站明日开幕!墨天轮将全程线上直播
  6. 【Linux】安装前的准备-----安装纯净版的虚拟机的步骤
  7. Python工作笔记002---PYTHON之DEF函数
  8. 笔记(2015.8.1)
  9. 带你走进P2P平台网站推广
  10. 封装pc端获取经纬度 百度地图
  11. 计算机软件后缀名,如何显示文件后缀名
  12. js渲染引擎 tempo.js
  13. Mybatis 从入门到入魔
  14. 分类变量、有序变量、数值变量差异分析(二)t检验
  15. 沉舟侧畔千帆过,病树前头万木春
  16. 幼儿园计算机培训心得,幼儿教师培训心得体会
  17. 树莓派3B Qt+dht11读取温湿度并写入数据库202005(8)
  18. 太阳能充电器带数显功能有什么用处?
  19. 获取数组最大值和最小值的简便方法
  20. unityhub是干什么的呀?unityhub的作用!

热门文章

  1. 【教学类-09-02】20221022《动物棋10*10 S形迷宫》(数字续写和骰子游戏)(大班主题《动物花花衣》)
  2. dubbogo 回顾与展望
  3. CocosCreator小游戏排行榜
  4. 嫌苹果鼠标(magic mouse)的灵敏度(跟踪速度)设置最大了都不够快,妙控板(magic trackpad)的灵敏度(跟踪速度)设置最大了都不够快(苹果鼠标/妙控板命令行设置灵敏度)
  5. 图片为什么要转化为base64格式
  6. 有多大的人格,做多大的事业!!
  7. 兔子繁殖问题,兔子有寿命限制
  8. AT89C51-科技外文文献
  9. 服务器系统盘选择,云服务器ecs选择什么系统盘
  10. 员工评价系统第一天,项目需求分析