1.匹配字符
.
\w, \W
\s, \S
\d, \D
[], [^]
\b, \B, ^, $
2.匹配次数
*, +, ?, {M,N}, {M,}, {,N}, {N}
3.分之
|
4.分组
()
\数字 --> 重复前面第几个分组匹配到的内容
def main():
re_str = r'(\d\d)\.[a-z]{2,3}'
print(re.fullmatch(re_str, '23.hj'))
result = re.findall(re_str, 's56fjh22.huk--=334.ko";sss;ss94.al////')
print(result)
# json数据处理
with open('data.txt', encoding='utf-8') as f:
# dict1 = json.load(f)
# for dict2 in dict1['data']:
# print(dict2['name'])
names = re.findall(r'"name":"(.*?)",', f.read())
print(names)
网友评论