I need to find a string for a few words.
import re
words = [{'word':'test1', 'case':False}, {'word':'test2', 'case':False}]
status = "test1 test2"
for w in words:
if w['case']:
r = re.compile("\s#?%s" % w['word'], re.IGNORECASE|re.MULTILINE)
else:
r = re.compile("\s#?%s" % w['word'], re.MULTILINE)
if r.search(status):
print "Found word %s" % w['word']
For some reason, it will only ever find "test2" and never "test1". Why is this?
I know I can use | markup, but there may be hundreds of words, so I use a for loop.
source
share