import re
regex = re.compile(r"(?<=Code:).*Distribution\s([\d.,]+)(?=\n)")
test_str = ("Code: 210 - Test 1 - Distribution\n"
"267745 Vis - Branch Deposit 3/10/2021 2,000.00\n"
"468040 v- Branch Deposit 2/10/2021 1,700.00\n"
"586075 Visa 3/3/2021 555.48\n"
"502490 Vis 3/4/2021 1,835.51\n"
"403195 Vis 3/4/2021 2,033.56\n"
"500230 Vis 3/4/2021 651.29\n\n"
"Code: 210 - Test - Distribution 8,775.84\n"
"Code: 230 - Greenville - Distribution\n"
"853955 Clearing 2/1/2021 77.50")
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