I'm reading in information from a .tsv file, getting a string representing a regex in each line. For example, I want to detect "remix" or "re-mix", so I read in '\bre-?mix\b'
and have to convert it. I searched a bit and found this question along the same lines, but I've tested the answers and none of it works for me.
When I use re.escape() on the pattern, it ends up like this: '\bre-\?mix\b', and after using re.compile() and doing a re.search() on "remix", it fails. I've tried simply inputting raw_regex.replace('\\b', '\\\\b')
into re.compile(), and checking the pattern, it looks as it's supposed to, yet still doesn't catch the simple if compiled_regex.search ("remix")
check.
What am I doing wrong here? All I need to do is read in raw text regexes, convert, and compile them. If something needs to be changed on the input end, that can be done as well. Thanks!