How to parse for tags with '+' in python

后端 未结 2 1134
一个人的身影
一个人的身影 2021-01-03 04:30

I\'m getting a \"nothing to repeat\" error when I try to compile this:

search = re.compile(r\'([^a-zA-Z0-9])(%s)([^a-zA-Z0-9])\' % \'+test\', re.I)
         


        
2条回答
  •  灰色年华
    2021-01-03 04:37

    Escape the plus:

    r'\+test'
    

    The plus has a special meaning in regexes (meaning "match the previous once or several times"). Since in your regex it appears after an open paren, there is no "previous" to match repeatedly.

提交回复
热议问题