I know how Python use "r" as the raw string notation in regular expression:
However, I'd like to apply that in a while loop like:
while i < len(organized_texts) and j < len(frag_texts):
if re.match(frag_texts[j], organized_texts[i]):
# If frag_texts[j] matches the beginning of organized_texts[i]
# Do things
The problem is that frag_texts[j]
can contain literal "(" and that's where re.match(frag_texts[j], organized_texts[i])
blows up with error: missing ), unterminated subpattern at position 2.
Apparently I can do neither rfrag_texts[j]
nor \frag_texts[j]
. I've tried re.match("r'{}'".format(frag_texts[j]), organized_texts[i])
but it gives me the same error too. What options do I have now?