I am using a regex and I get the error:
Traceback (most recent call last):
File \"tokennet.py\", line 825, in
RunIt(ContentToRun,Content
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: