我正在尝试编译一个正则表达式,以便能够r'#\w+'从推文中累积一系列主题标签 ()。我希望能够编译两个正则表达式,它们可以从推文的开始和结束来做到这一点。我正在使用 python 272,我的代码是这样的。
HASHTAG_SEQ_REGEX_PATTERN           = r"""
(                                       #Outermost grouping to match overall regex
#\w+                                    #The hashtag matching. It's a valid combination of \w+
([:\s,]*#\w+)*                          #This is an optional (0 or more) sequence of hashtags separated by [\s,:]*
)                                       #Closing parenthesis of outermost grouping to match overall regex
"""
LEFT_HASHTAG_REGEX_SEQ      = re.compile('^' + HASHTAG_SEQ_REGEX_PATTERN , re.VERBOSE | re.IGNORECASE)
当我正在编译正则表达式的行被执行时,我收到以下错误:
sre_constants.error: unbalanced parenthesis
我不知道为什么会这样,因为在我的正则表达式模式中没有看到不平衡的括号。