import re
#普通匹配
findall = re.findall("hello", "hello python")
# 匹配开头
findall = re.findall("^hello", "hello python")
# 多行匹配
findall = re.findall(r"^hello", "hello python\nhello",flags=re.MULTILINE)
# 匹配结尾
findall = re.findall("python$", "hello python")
# 匹配数字
findall = re.findall("\d","abd123efg") #['1', '2', '3']
findall = re.findall("\d+","abd123efg") #['123']
# 匹配字母和数字
findall = re.findall("\w+","abd123efg¥")
# 只匹配字母
findall = re.findall("[a-z]+","abd123efg¥") #['abd', 'efg']
# 匹配括号,需要转义
findall = re.findall("\(","abd123(efg¥") #['(']
print(findall)
python的re模块-- 第三讲
最新推荐文章于 2023-08-03 18:16:39 发布