import re
regex = re.compile(r"(?ms)^\s{,20}\d.*?(?=^\s{,20}\d|\Z)", flags=re.MULTILINE)
test_str = (" BID RANK BID TOTAL BIDDER ID BIDDER INFORMATION (NAME/ADDRESS/LOCATION)\n"
" -------- ----------- --------- -------------------------------------------------\n"
" 1 1,486,399.87 5 ORTIZ ASPHALT PAVING INC 909 386-1200 SB PREF CLAIMED\n"
" 00814766\n"
" P O BOX 883 FAX 909 386-1288\n"
" COLTON CA 92324\n\n"
" 2 1,534,243.00 3 EXCEL PAVING COMPANY 562 599-5841 SB PREF CLAIMED\n"
" 00688659\n"
" 2230 LEMON AVENUE FAX 562 591-7485\n"
" LONG BEACH CA 90806\n\n"
" 3 1,593,549.40 2 SECURITY PAVING COMPANY INC 818 767-8418 CC PREF CLAIMED\n"
" 00116307\n"
" P O BOX 1489 FAX 818 767-3169\n"
" SUN VALLEY CA 91353-1489")
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