import restr = 'i mrnaive python3.8'# match从左边开始匹配print('--------match--------')res = re.match('i', str)print(res.group())# 查找字符串中的单个符合条件的字符print('--------search--------')res2 = re.search('mrnaive', str)print(res2.group())# 查找字符串中多个符合条件的字符print('--------findall--------')res3 = re.findall('n', str)print(res3)# 按需求匹配print('--------test--------')str2 = '<div><a style="color:#cccccc" href="http://www.baidu.com">百度</a></div>'res4 = re.findall('<a style="color:#cccccc" href="(.+)">(.+)</a>', str2)print(res4)# 字符串替换print('--------sub--------')sul = re.sub('style=\S+', '', str2)print(sul)