The following regular expression is not returning any match:
import re
regex = '.*match.*fail.*'
pattern = re.compile(regex)
text = '\ntestmatch\ntestfail'
match = pattern.search(text)
I managed to solve the problem by changing text
to repr(text)
or setting text as a raw string with r'\ntestmatch\ntestfail'
, but I'm not sure if these are the best approaches. What is the best way to solve this problem?