匹配邮箱
import re
mylist = ['aaa@163.com', 'bbb@126.com', 'ccc@qq.com']
for i in mylist:
match_obj = re.match('\w{3,15}@(163|162)\.com$',i)
if match_obj:
print(match_obj.group())
print(match_obj.group(1))
else:
print('没有匹配')
匹配网页
import re
content = '<htm1>hello world!</html>'
obj = re.match('<[a-zA-Z0-9]+>(.*)</[a-zA-Z0-9]+>')
if obj:
print(obj.group(1))
else:
print('0')
匹配电话号码
import re
list = ['010-12345','010123456']
for i in list:
obj = re.match('^0[0-9]{2,3}-?\d{5}',i)
if obj:
print(obj.group())