Python3学习--正则表达式

import re

r = re.match("Chen\d+","Chen123ronghua123")
r = re.match(".+","Chen123ronghua123")

r = re.search("r[a-zA-Z]+","Chen123ronghUa123")
r = re.search("#.+#","1233#hello###")
r = re.search("a+","aaabbbccc")
r = re.search("[0-9]{1,3}","a1aab3bb454ccc") #匹配指定次数

r = re.findall("[0-9]{1,3}","a1aab3bb454ccc") #查找全部

r = re.search("abc|ABC","abcABCsdfs") #或匹配
r = re.search("(abc){2}","abcabcABCsdfs") #分组匹配
r = re.search("(?P<id>[0-9]{3})","abc234abcABCsdfs")#赋值
r = re.split("[0-9]","abc2fds3sf4") #分割

r = re.sub("[0-9]+","|","dsfsaf23kdk33Dfdf34fdsf",count=2) #替换,匹配所有数字替换成管道符号,替换2次

#print(r.groupdict())
print(r)
posted @ 2017-02-10 17:24  hanfuming  阅读(227)  评论(0编辑  收藏  举报