参考博客原址:https://blog.csdn.net/YZXnuaa/article/details/79346963
<link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/ck_htmledit_views-5edb848729.css">
<div class="htmledit_views" id="content_views">
<pre>正则 re.findall 的简单用法(返回string中所有与pattern相匹配的全部字串,返回形式为数组)
语法:
1
|
findall(pattern, string, flags
=
0
)
|
import re
Python 正则表达式 re findall 方法能够以列表的形式返回能匹配的子串
print (help(re.findall))
print (dir(re.findall))
findall查找全部r标识代表后面是正则的语句
1
2
3
|
print
(regular_v1)
# [‘docs’]
|
符号^表示匹配以https开头的的字符串返回,
1
2
3
|
print
(regular_v2)
# [‘https’]
|
用 ",
“https://docs.python.org/3/whatsnew/3.6.html”
)
(regular_v3)
# [‘html’]
# […]匹配括号中的其中一个字符
123(regular_v4)
# [‘th’, ‘wh’]
“d”是正则语法规则用来匹配0到9之间的数返回列表
123456(regular_v5)
# [‘3’, ‘3’, ‘6’]
(regular_v6)
# [‘123’]
小d表示取数字0-9,大D表示不要数字,也就是出了数字以外的内容返回
123(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
123(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”在正则里面代表匹配除了字母与数字以外的特殊符号
123(regular_v9)
# [’:’, ‘/’, ‘/’, ‘.’, ‘.’, ‘/’, ‘/’, ‘/’, ‘.’, ‘.’]
<link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/ck_htmledit_views-5edb848729.css">
<div class="htmledit_views" id="content_views">
<pre>正则 re.findall 的简单用法(返回string中所有与pattern相匹配的全部字串,返回形式为数组)