美文网首页每天写500字每周500字每天写1000字
python 31:匹配中国电话号码和美国电话号码的正则表达式

python 31:匹配中国电话号码和美国电话号码的正则表达式

作者: 金石明镜 | 来源:发表于2019-12-18 20:27 被阅读0次

一、中国电话号码

chinesePhoneRegex = re.compile(r'''( (0[1-9]{2,3})? # area code

(\s|-|\.)? # separator

(\d{11}|\d{8}) #8digits pr 11digits

)''',re.VERBOSE)

二、美国电话号码

americaPhoneRegex = re.compile(r'''( (\d{3}|\(\d{3}\))? # area code

(\s|-|\.)? # separator

\d{3} # first 3 digits

(\s|-|\.) # separator

\d{4} # last 4 digits

(\s*(ext|x|ext.)\s*\d{2,5})? # extension

)''',re.VERBOSE)

相关文章

网友评论

    本文标题:python 31:匹配中国电话号码和美国电话号码的正则表达式

    本文链接:https://www.haomeiwen.com/subject/smxpnctx.html