i'm looping through strings in the list "titles" and i want to print the string which word matches in "keywords_to_match":
# import re
titles = ['walk to new zealand' , 'fly to mars' , 'drive to murica']
keywords_to_match = re.compile(r'(new zealand)?(mars)?(murica)')
for title in titles:
# if any of words inside keywords_to_match are matched print title
if keywords_to_match.search(title.lower()):
print(title)
# only prints "drive to murica"
this only prints "drive to murica" but i expect it to print all 3 of the strings inside "titles".