# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(\b\d\d[-|\s]\d\b)\s(\b[a-z]+\b)"
test_str = ("57-61 P D DeS, 62-4 Dodge 880, 57-64 C\n\n\n\n\n\n\n\n"
"39-56 P, D, 40-52 DeS, 53-4 DeS except wagon, 55-6 DeS Fireflite, 55-6 DeS Firedome except wagon, 40-52 C 6 cyl, 53-6 C except Imp, wagon, LWB\n\n"
"57-8 C, I, 60 with model E AC, PP2, PD4, High Performance, PD1, PD2, PS1, PS3, PC1, PC2, PC3, PY1, 61 with model F AC RP2 Hipo, DeS, C, Imp, 61 Dart 6, 62 P, D 6 without air, 62 C 300 and Newport, 62 P, D with 361, 63 P, D 6 62 P Valiant, Lancer with model G AC, 64 Val, Dart 273, 318, VD2 361, 383 with air and towing, 65 P, D all with 273, 318 and no air, 63-8 DT C500 with 318 and air, 69 P, D exc. Belv. Cor, 70-72 B,J,R,W with 318, 73 B,J,R,W,P,D with 318, 360")
matches = re.finditer(regex, test_str, re.MULTILINE | re.IGNORECASE)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
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