写了错误的正则表达式
1、 后带数量
将d 误写成了 , 尷尬!
>>> pattern = re.compile(r'123*hello')
输出:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "E:Anacoda3Lib
e.py", line 233, in compile
return _compile(pattern, flags)
File "E:Anacoda3Lib
e.py", line 301, in _compile
p = sre_compile.compile(pattern, flags)
File "E:Anacoda3Libsre_compile.py", line 562, in compile
p = sre_parse.parse(p, flags)
File "E:Anacoda3Libsre_parse.py", line 856, in parse
p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, False)
File "E:Anacoda3Libsre_parse.py", line 415, in _parse_sub
itemsappend(_parse(source, state, verbose))
File "E:Anacoda3Libsre_parse.py", line 615, in _parse
source.tell() - here + len(this))
sre_constants.error: nothing to repeat at position 2
报错原因:由于 为单词边界, * 的含义为出现任意次,也就是说, 单词只能有一个边界,不可能出现任意次,所以会报这个错