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

Python 正则表达式 re findall 方法能够以列表的形式返回能匹配的子串

# print (help(re.findall))
# print (dir(re.findall)) findall查找全部r标识代表后面是正则的语句
regular_v1 = re.findall(r"docs","https://docs.python.org/3/whatsnew/3.6.html")
print (regular_v1)
# ['docs']

符号^表示匹配以https开头的的字符串返回,
regular_v2 = re.findall(r"^https","https://docs.python.org/3/whatsnew/3.6.html")
print (regular_v2)
# ['https']

  

用$符号表示以html结尾的字符串返回,判断是否字符串结束的字符串
regular_v3 = re.findall(r"html$","https://docs.python.org/3/whatsnew/3.6.html")
print (regular_v3)
# ['html']

# [...]匹配括号中的其中一个字符
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之间的数返回列表
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表示不要数字,也就是出了数字以外的内容返回
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
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”在正则里面代表匹配除了字母与数字以外的特殊符号
regular_v9 = re.findall(r"\W","https://docs.python.org/3/whatsnew/3.6.html")
print (regular_v9)
# [':', '/', '/', '.', '.', '/', '/', '/', '.', '.']

正则表达式 re.findall 用法的更多相关文章

  1. python中正则表达式 re.findall 用法

    在python中,通过内嵌集成re模块,程序媛们可以直接调用来实现正则匹配. 其中,re.findall() 函数可以遍历匹配,可以获取字符串中所有匹配的字符串,返回一个列表. 在python源代码中 ...

  2. oracle正则表达式regexp_like的用法详解

    oracle正则表达式regexp_like的用法详解 /*ORACLE中的支持正则表达式的函数主要有下面四个:1,REGEXP_LIKE :与LIKE的功能相似2,REGEXP_INSTR :与IN ...

  3. [C#]正则表达式的基本用法

    C#正则表达式的基本用法 正则表达式(regular expression)描述了一种字符串匹配的模式(pattern),可以用来检查一个串是否含有某种子串.将匹配的子串替换或者从某个串中取出符合某个 ...

  4. Python正则表达式re.findall("[A-Za-z]([A-Za-z0-9])*[.]txt",'Abc2019.txt')的结果为什么是['9']

    在<Python妙用re.sub分析正则表达式匹配过程>中老猿分析了findall函数的返回情况,老猿前一阵子在执行这个语句时: >>> re.findall(" ...

  5. Python的re模块,正则表达式用法详解,正则表达式中括号的用法

    Python的re模块,正则表达式 #导入re模块 import  re 1.match方法的使用: result = re.match(正则表达式,待匹配的字符串) 正则表达式写法: 第一部分: 字 ...

  6. 关于C#List中FindAll用法的一些简单示例

    using System; using System.Collections.Generic; public partial class List : System.Web.UI.Page { pro ...

  7. JS种正则表达式的基础用法

    基础语法 元字符 常用元字符 含义 . 匹配除换行符以外的任意字符 \w 匹配字母数字或下划线 \W 匹配不是字母.数字.下划线的字符 \d 匹配数字,相当于[0-9] \D 匹配不是数字的字符 \s ...

  8. Learning Python 008 正则表达式-002 findall()方法

    Python 正则表达式 - findall()方法 重点 findall()方法的使用 - 程序讲解 简单的符号的使用 正则表达式的库文件是re,先导入库文件: import re .的使用举例 # ...

  9. python正则表达式(5)--findall、finditer方法

    findall方法 相比其他方法,findall方法有些特殊.它的作用是查找字符串中所有能匹配的字符串,并以结果存于列表中,然后返回该列表 注意: match 和 search 是匹配一次 finda ...

随机推荐

  1. undo与redo

    http://www.cnblogs.com/HondaHsu/p/3724815.html

  2. 语法的二义性和token的超前扫描

    语法的二义性 JavaCC不能分析所有EBNF描述的语法,因为EBNF描述的语法本质上具有二义性的情况.C语言中if语句用JavaCC的EBNF可以是如下描述: "if" &quo ...

  3. 三种不同类型的ssh隧道

    何谓SSH隧道 隧道是一种把一种网络协议封装进另外一种网络协议进行传输的技术.这里我们研究ssh隧道,所以所有的网络通讯都是加密的.又被称作端口转发,因为ssh隧道通常会绑定一个本地端口,所有发向这个 ...

  4. Galera Cluster mysql+keepalived集群部署

    1.卸载mysql 查找本机安装的mysqlrpm -qa | grep -i mysql --nodeps --force rpm -ev MySQL-server-5.6.15-1.el6.x86 ...

  5. mybatis14--注解的配置

    去掉对应的mapper映射文件 在dao文件中增加注解 public interface StudentDao { /** * 新增学生信息 */ @Insert(value="insert ...

  6. [转] - Weiflow——微博机器学习框架

    Weiflow--微博机器学习框架 本文从开发效率(易用性).可扩展性.执行效率三个方面,介绍了微博机器学习框架Weiflow在微博的应用和最佳实践. 在上期<基于Spark的大规模机器学习在微 ...

  7. 半夜两点灵光一现想出来的一个demo

    功能: 1.用户通过页面下载Excel模板,按照模板填写数据,上传Excel , 服务器解析 ,绘制成折线图.柱状图.雷达图 ....... 2.用户在线编辑数据,绘图 (没想好咋弄) 可定制需求,根 ...

  8. juqery 回车事件 回车操作 回车搜索

    html <form class="search_wrap" method="post" action=""> <div ...

  9. javascript的数组之sort()

    sort()方法用in-place的算法对原数组进行排序,但不会产生新的数组.这个方法不是一个稳定的排序,默认采用的是安字符串Unicode码点进行排序的. let fruit =  ['cherri ...

  10. Linux命令 sed

    一. 以行为单位进行操作. d:删除 $ nl passwd | sed '2,5d'  # 删除第2~5行 $ nl passwd | sed '2d'  # 删除第2行 $ nl passwd | ...