import re
regex = re.compile(r"(?<=\d-)\d+|\d+(?=-\d+)|\d+(?=(?:\/\d+)*b)")
test_str = ("Name 789, 10-mill 12-27b\n"
"Manufacturer XY-2822, 10-mill, 17-25b\n"
"Other Manufacturer 16b Part\n"
"Another Manufacturer FER M9000, 11-mill, 11-40\n"
"18b Part\n"
"Maker 11-31, 10-mill\n"
"Maker 1x or 2x; max size 1x (34b), 2x (38/24b)\n"
"Maker REC6 15/18/26b. Square.\n"
"Producer FC-40 11-13-16-19-22-25-27-30-34b")
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