此正则表达式与来自北美的典型电话号码匹配
匹配3334445555、333.444.5555、333-444-5555、3334445555,(333)4445555及其所有组合,例如333
4445555,(333)4445555或333444-5555。与国际符号+13334445555不匹配,但与+1 333
4445555中的国内部分匹配。
(?b[2-9][0-9]{2})?[-. ]?[2-9][0-9]{2}[-. ]?[0-9]{4}b资料来源:RegexBuddy
以下Python代码遍历所有匹配项
for match in re.finditer(r"(?b[2-9][0-9]{2})?[-. ]?[2-9][0-9]{2}[-. ]?[0-9]{4}b", subject): # match start: match.start() # match end (exclusive): match.end() # matched text: match.group()您期望什么模式?



