【发布时间】:2018-05-21 09:27:17
【问题描述】:
我尝试匹配+和h之间的所有子字符串,例如+abcd1234h。
代码如下:
match = re.match(r'.*+(.*)h.*',line)
错误发生如下,当我运行我的代码时:
File "C:\Program Files\Python\Python36\lib\re.py", line 172, in match
return _compile(pattern, flags).match(string)
File "C:\Program Files\Python\Python36\lib\re.py", line 301, in _compile
p = sre_compile.compile(pattern, flags)
File "C:\Program Files\Python\Python36\lib\sre_compile.py", line 562, in compi
le
p = sre_parse.parse(p, flags)
File "C:\Program Files\Python\Python36\lib\sre_parse.py", line 855, in parse
p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, 0)
File "C:\Program Files\Python\Python36\lib\sre_parse.py", line 416, in _parse_
sub
not nested and not items))
File "C:\Program Files\Python\Python36\lib\sre_parse.py", line 619, in _parse
source.tell() - here + len(this))
sre_constants.error: multiple repeat at position 2
似乎是正则表达式错误,如何解决? .
【问题讨论】:
标签: python regex python-3.x