![在这里插入图片描述](https://img-blog.csdnimg.cn/20190513213512255.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2NoZW5faG9seQ==,size_16,color_FFFFFF,t_70)
结合|,实现多邮箱匹配
import re
"""
匹配出163邮箱,且@符号之前有4-20位英文字母数字或下划线
"""
email1 = "hello@qq.com"
email2 = "hello@163.com"
email3 = "hello@123.com"
ret = re.match("^[a-zA-Z0-9_]{4,20}@(163|123|qq)\.com$", email1)
if ret:
print("正确,", ret.group())
else:
print("不正确")
取分组内的匹配到的值
ret = re.match("^[a-zA-Z0-9_]{4,20}@(163|123|qq)\.com$", "1377302230@qq.com")
print(ret.group(1))
html标签一致匹配
ret = re.match(r'<([a-zA-Z]*)>.*</\1>', '<html>hello beauty</html>')
print(ret.group())
ret = re.match(r'<(?P<p1>[a-zA-Z]*)>.*</(?P=p1)>', '<html>hello beauty</html>')
print(ret.group())