import re
# o = "hello meiyu abc def ads 1966"
1、# # re.match()#从头匹配1简单2分组
# r = re.match("h\w+",o)
#
# print(r.group())#获取匹配到的所有结果
# r = re.match("(h\w+)",o)
# print(r.groups())#获取模型匹配到的分组结果
# r = re.match("(?P<n1>h\w+)",o)
# print(r.groupdict())#获取模型中匹配到的分组中所有执行了key的结果
#有分组,提取匹配成功的指定内容
2、# re.search()#浏览全部字符串,匹配第一个符合规则的字符串
# re.findall()#将匹配到的所有内容都放置在一个列表中
# a = re.findall("\d+\w\d+","a2c3s1d1")
# print(a)
# a = re.findall("(\d+)(\w*)(\d+)","a2c3s1d1")
# print(a)
3、# re.finditer()#迭代
# a = re.finditer("(\d+)(\w*)(\d+)","a2c3s1d1")
# print(a)
# for i in a:
# print(i,i.group(),i.groups(),i.groupdict())
4、# re.split()#分割
# a = re.split("(a\w+)",o,1)
# print(a)
# def f(ex):
# return 1
5、##计算器
# o = "1-5*(58*(4+5*(24*21/(5-2))))*55"
# while True:
# print(o)
# r = re.split("\(([^()]+)\)",o,1)#[]表示不包含
# if len(r) == 3 :
# a = r[0]
# b = r[1]
# c = r[2]#等效于a,b,c = r
# o = a + str(f(b)) + c
# else:
# print(f(o))
# break
6、# re.sub()替换
# new = re.sub("\d+","kkk",o)
# print(new)
#re.subn()
# new,count = re.subn("\d+","kkk",o)
# print(new,count)