-3
我有这样的正则表达式/ Python代码:Python的正则表达式:sre_constants.error:不平衡括号
REGISTRY_REGEX = re.compile("((HKEY(?:_\w+)+|HK[CLU][RUMC])\\([a-zA-Z\d\/\\.{}\s-]+))")
这应该符合这个字符串:
HKLM\SYSTEM\CurrentControlSet\Services\aRandomServiceName
当我运行我的python脚本,它返回:
Traceback (most recent call last):
File "regex_id.py", line 11, in <module>
REGISTRY_REGEX = re.compile("((HKEY(?:_\w+)+|HK[CLU][RUMC])\\([a-zA-Z\d\/\\.{}\s-]+)))")
File "/usr/lib/python2.7/re.py", line 194, in compile
return _compile(pattern, flags)
File "/usr/lib/python2.7/re.py", line 251, in _compile
raise error, v # invalid expression
sre_constants.error: unbalanced parenthesis
这个正则表达式似乎在RegExr中工作,我错过了什么?
中的问题,并在堆栈跟踪正则表达式是不同的。堆栈跟踪中的最后有''''。 – ndn
UNESCAPE的(.. –
我试过你的模式前添加'r'这样说:'re.compile(R“((HKEY(?:_ \ w +)+ |香港[CLU] [RUMC])\\ ([A-ZA-Z \ d \/\\ {} \ S - ] +)))“)'有错误信息不见了 –