I have multiple patterns to check against. Say hello and bye, but will be many more, so I chose to use re.compile() to store them and then being able to check this regex:
import re
mypatt = re.compile(r'(hello|bye)', re.IGNORECASE)
url = ["bye bye", "hello how are you", "i am fine", "ok byeee"]
for u in url:
if mypatt.search(u):
print "yes --> %s" %(u)
Upon running this code I get the desired output:
yes --> bye bye
yes --> hello how are you
yes --> ok byeee
However, since there are multiple patterns I would like to write one per line, with something like:
mypatt = re.compile(r'(\
hello|\
bye\
)', re.IGNORECASE)
However this does not work and I cannot understand why. What is the way to write such statement, writing every pattern in a different line?
re.VERBOSEflag to ignore unescaped whitespace, I think.re.compile(r"""( ... )""", re.IGNORECASE |re.VERBOSE)made it. Feel free to post it as an answer if you want.