我正在将 C# 函数转换为 Python。它应该是与现有功能兼容的错误。
这是该函数中的正则表达式:http://[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)+([-A-Z0-9a-z_$.+!*()/\\\,:;@&=?~#%]*)*
. 但是 Python 无法编译它:
>>> re.compile(r"http://[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)+([-A-Z0-9a-z_$.+!*()/\\\,:;@&=?~#%]*)*")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.3/re.py", line 214, in compile
return _compile(pattern, flags)
File "/usr/lib/python3.3/re.py", line 281, in _compile
p = sre_compile.compile(pattern, flags)
File "/usr/lib/python3.3/sre_compile.py", line 498, in compile
code = _code(p, flags)
File "/usr/lib/python3.3/sre_compile.py", line 483, in _code
_compile(code, p.data, flags)
File "/usr/lib/python3.3/sre_compile.py", line 75, in _compile
elif _simple(av) and op is not REPEAT:
File "/usr/lib/python3.3/sre_compile.py", line 362, in _simple
raise error("nothing to repeat")
sre_constants.error: nothing to repeat
注意:该正则表达式有一个 JavaScript 版本:/http:\/\/[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)+([-A-Z0-9a-z\$\.\+\!\_\*\(\)\/\,\:;@&=\?~#%]*)*/gi
.
我搜索了大约
对不起,这是一个重复的帖子。nothing to repeat
错误,但一无所获。
问题出在哪里?