I'm using the following to find whether a text exist in the sentence and printing out that text:
Example:
import re
lst = ['text1','text2','text3']
sent = 'This is a test to find text1 and text3'
my_regex =re.search(r'\b(text1)\b', sent)
print(my_regex.group())
text1
Question:
is it possible to create a loop similar to the following that will iterate and update the re.search with each value in the list:
note - The list is likely to expand beyond the three listed in the example
for i in lst:
my_regex =re.search(r'\b(i)\b', sent)
print(my_regex.group())
r'\b' + i + r'\b'?r'\b(text1|text2|text3)\b'. Have you tried that?