I am trying to run regex to retrieve an output.
import re
text = """
x
abc123
abc
ddddd
wtf
xyz
"""
# Regex pattern to match sequences between 'abc' and 'xyz' inclusively
pattern = r'(?s)(abc.*?xyz)'
# Find all matches using re.findall
matches = re.findall(pattern, text)
# Print the matches
for match in matches:
print(match)
print()
I want the output to be
abc123
abc
ddddd
wtf
xyz
and
abc
ddddd
wtf
xyz
but I am only getting
abc123
abc
ddddd
wtf
xyz
What mistake am I making? Why is it not also extracting the 2nd output?