import re
regex = re.compile(r"^.+,.+\n.+\n.+\n\s", flags=re.MULTILINE)
test_str = ("...\n"
"830 ORLANDO, 382.000CS $ \n"
"FL 16.2400 \n"
"840 TAMPA, FL 382.000CS $ \n"
"16.2400 \n"
"Subtotal 41,310.000CS \n"
"Contract Total 115,560.000CS $ 1,569,663.00 \n\n"
" \n"
"Contractor Total 115,560.000 C S $ 1,569,663.00 \n"
"ABC, INC. \n"
"PO Box 11 \n"
"NEW YORK, NY 11111-1111 \n"
" \n"
" \n"
"SOME RANDOM COMMODITY \n"
"90 New York, NY 39,900.000LB $ \n"
"0.4925 \n"
"110 CLEVELAND, OH 39,900.000LB $ \n"
"0.4925 \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