以下为代码
import re
pattern =r'(13[4-9]\d{8}$|(15[01289]\d{8})$'
mobile = '13634222222'
match = re.match(pattern,mobile) #进行模式匹配
if match == None: #判断 是否为None,为真表示匹配失败
print(mobile,'不是有效的中国移动电话号码')
else:
print(mobile,'是有效的中国电话号码')
mobile = '13144222221'
match = re.match(pattern,mobile) #进行模式匹配
if match == None: #判断 是否为None,为真表示匹配失败
print(mobile,'不是有效的中国移动电话号码')
else:
print(mobile,'是有效的中国电话号码')
以下为报错
Traceback (most recent call last):
File "C:\Users\LX\Documents\py\0819.py", line 23, in <module>
match = re.match(pattern,mobile) #进行模式匹配
File "C:\Users\LX\Documents\py\lib\re.py", line 190, in match
return _compile(pattern, flags).match(string)
File "C:\Users\LX\Documents\py\lib\re.py", line 303, in _compile
p = sre_compile.compile(pattern, flags)
File "C:\Users\LX\Documents\py\lib\sre_compile.py", line 764, in compile
p = sre_parse.parse(p, flags)
File "C:\Users\LX\Documents\py\lib\sre_parse.py", line 948, in parse
p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
File "C:\Users\LX\Documents\py\lib\sre_parse.py", line 443, in _parse_sub
itemsappend(_parse(source, state, verbose, nested + 1,
File "C:\Users\LX\Documents\py\lib\sre_parse.py", line 836, in _parse
raise source.error("missing ), unterminated subpattern",
re.error: missing ), unterminated subpattern at position 0
求问哪里有问题呢