sre_constants.error: nothing to repeat

前端 未结 1 1573
天命终不由人
天命终不由人 2021-01-20 12:41

I am using a regex and I get the error:

Traceback (most recent call last):
  File \"tokennet.py\", line 825, in 
    RunIt(ContentToRun,Content         


        
1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-20 13:28

    I suggest you to use re.escape(word), since your variable word may contain any regex special characters. I think the error came because of special characters present inside the variable. By using re.escape(variable-name), it escapes any special characters present inside the variable.

    if re.search(r'\b'+re.escape(word)+r'\b', str1) and re.search(r'\b'+re.escape(otherWord)+r'\b', str1) and word != otherWord:
    

    0 讨论(0)
提交回复
热议问题