1.正则表达式常用函数
1)re.match(pattern,string,flag)#(正则表达式,源字符,可选参数对应的标志位)
2)全局匹配函数
import re
string="apythonhellomypythonhispythonourpythonend"
pattern=re.compile(".python.")#预编译
result=pattern.findall(string)#找出符合模式的所有结果
print(result)
3)re.sub(pattern,rep,string,max)#(正则表达式,源字符,替换字符,最多替换次数)
实例:
正则表达式常用内容:
a.不能出现空格[^\s]*
b.以.com或者.cn结尾[.com|.cn]
c.任意的字母组合包括大小写[a-zA-Z]
d.匹配电子邮件\w+([.+-]\w+)*@\w+([.-]\w+)*\.\w+([.-]\w+)*