import re
my_str = """Hi my name is John...
My email is hdjjkd@cdc.com. I like playing
sports.
"""
endings = [
"John",
"hdjjkd@cdc.com",
"playing"
]
for ending in endings:
esc_ending = re.escape(ending)
result = re.match(".*?" + esc_ending, my_str, re.X|re.M|re.S)
if result:
print(result.group(0))
print("~" * 30)
--output:--
Hi my name is John
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Hi my name is John...
My email is hdjjkd@cdc.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Hi my name is John...
My email is hdjjkd@cdc.com. I like playing
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~