import re
regex = re.compile(r"Current File:[ \t]*(\S+\.txt)[^O]*(?:O(?!ld File)|[^O])+ Old File:[ \t]*(\S+\.txt).*(?:\r?\n(?!--).*)*(?=\r?\n--)", flags=re.MULTILINE)
test_str = ("Current File: week-28\\gcweb.txt (=>) ########## Old File: week-27\\gcweb.txt (<=)\n\n\n\n"
"2019-07-21 13:20:42 ip-172-17-3-71=>\n"
"2019-07-17 13:27:12 ip-172-17-3-71<=\n"
"--------------------------------------------------\n"
"--------------------------------------------------\n"
"Current File: week-28\\gcckup.txt (=>) ########## Old File: week-27\\gcckup.txt (<=)\n\n\n\n"
"2019-07-21 13:20:46 ip-172-17-2-101=>\n"
"2019-07-17 13:27:14 ip-172-17-2-101<=\n"
"--------------------------------------------------\n"
"--------------------------------------------------")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html