3.7 python 中 用正则表达式 邮箱及电话号码的匹配

import re
c = re.compile(r'^\w+@(\w+\.)+(com|cn|net|edu)$')
# string = ' [email protected]'
string = '[email protected]'
s = c.search(string)
if s:
    print(s.group())
    print(s.span())

# 手机号码的匹配

import  re
c = re.compile(r'^1[3-9]\d{9}$')
s = c.search('16638214761')
if s:
    print(s.group())

猜你喜欢

转载自blog.csdn.net/XC_LMH/article/details/81503888