import re
regex = re.compile(r"(.+\n.+\n)(\d+\.\d{1,2})", flags=re.MULTILINE)
test_str = ("RETAIL\n"
"UPRICE QTY TOTAL\n"
"ILLUSTRATION BOARD 15X20 (1/4 SIZE ) BY\n"
"1276\n"
"12.50 1.0 12.50\n"
"MONGOL PENCIL 1,2,3 PC\n"
"434\n"
"6.50 1.0 6.50\n"
"MS 300 (MGK) PERMANENT MARKER\n"
"1470\n"
"3.75 1.0 3.75\n"
"HBW White Glue 40 grans\n"
"1690\n"
"10.00 1.0 10.00\n"
"COLOR PEN 8 COLORS (VARIOUS BRAND)\n"
"1930\n"
"16.50 1.0 16.50\n"
"KS /CREATION CONSTRUCTION PAPER (105)\n"
"3503\n"
"23.00 1.0 23.00")
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