python中最常用的re正则表达式总结

import re
x = re.search('r\D+a','123chenronghua')
print(x.group())
s = re.search('r[a-z]+a','123chenronghua')
print(s.group())
z = re.search('r[a-z]+a$','123chenronghuazhaobaoyua').group()
print(z)
c = re.search('r[a-z]+a','123chenronghua123zhaobaoyua').group()
print(c)


#f = re.search('aaa?','aalixaaa')#?匹配?前面的字符一次或零次
#print(f.group())#执行结果aa  因为第三个a匹配了零次,优先匹配前面的 数组
g = re.search("[0-9]{3}","m1a2k145search")
print(g.group())
g = re.findall("[0-9]{1,3}","m1a2k345search")
print(g)
f = re.search('aaa?','aalixaaa')#?匹配?前面的字符一次或零次
print(f.group())#执行结果aa  因为第三个a匹配了零次,优先匹配前面的 数组

p = re.search("(?p[a-z]{9})(?p[0-9]{2})","zhaobaoyu23").groupdict()
print(p)

split的数字分割符
L = re.split("[0-9]+","zhao1bao2yu3is4haoren")
print(L)

你可能感兴趣的:(python中最常用的re正则表达式总结)