python 正则

正则

常用方法

1.findall()

返回结果为列表

'''
内容提取
'''
data='window.QRLogin.code = 200; window.QRLogin.uuid = "gbGEZLvmhQ==";'
import re
ret=re.findall('uuid = "(.*)"',data)
print(ret)
'''
结果
['gbGEZLvmhQ==']
'''
View Code

2.search()

3.match

方法试图从字符串的起始部分对模式进行匹配。

 4.group

用于选择匹配

5.groups

6.compile

"""
Python re校验手机号
"""
import re

r = re.compile(r'^1[3-9][0-9]{9}$')
print(r.match("12211111111"))
print(r.match("13211111111"))
print(r.match("1a211111111"))
View Code

用于提取

文档:https://docs.python.org/zh-cn/3/library/re.html

参考https://segmentfault.com/a/1190000015123481

原文地址:https://www.cnblogs.com/huay/p/11625457.html