I have an array of strings that I want to match in python. Is there a way to do this without using for loops?
All the examples I have seen so far are like the following, where you have to loop through each element to find a match:
import re
patterns = [ 'this', 'that' ]
text = 'Does this text match the pattern?'
for pattern in patterns:
print 'Looking for "%s" in "%s" ->' % (pattern, text),
if re.search(pattern, text):
print 'found a match!'
else:
print 'no match'
Would it be possible to do this without using a for loop