# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(\d{5,}\S+)(?:-REV)|(\d{5,})|(\d.+)(?:-REV).+|(\b[A-Za-z0-9]+-[A-Za-z0-9]+-[A-Za-z0-9]+\b)|(\d{4,}.\S+)"
test_str = ("SIEMENS10249071REV05\n"
"22D1496-REV-A\n"
"SANTASISE398FOP4\n"
"KCC C318-M-2328\n"
"22006-17114-REV-0\n"
"WELD30\n"
"2328ENDFIN\n"
"OSH4780973\n"
"10520398ITEM7\n"
"KCC C153-M-136290\n"
"2373 TAPER\n"
"SANTA ISE398 R2\n"
"SANTASISE398RGH1\n"
"34F0-010-102-REV-WELDMENT\n"
"14A1936D1F1-REV-NONE\n"
"6181194-REV-B\n"
"PRETE WT-80-1015BLIND\n"
"MAXAM340000566\n"
"SHARPE-36465 1ST\n"
"OSH 3899580\n"
"7494-03-301-REV-NONE\n"
"MAXAM340000566OP2\n"
"KCC C318-M-2373TAPER\n"
"CARDINAL36465\n"
"SIEMENS-10248227 REV.8\n"
"4212.8842-REV-Q\n"
"14A1936-REV-NONE\n"
"LATHE TOOL\n"
"360 YIELD 450111 RH MAIN PROGRAM;360 YIELD 450111 LH MAIN PROGRAM;450111\n"
"KCC C318-M-2373\n"
"360 YIELD 450211 RH MAIN PROGRAM;360 YIELD 450211 LH MAIN PROGRAM;450211\n"
"360 YIELD 450101 LH MAIN PROGRAM;450101\n"
"10753289-REV-02\n"
"30613D3-REV-05\n"
"30613D4-REV-05\n"
"OSHKOSH CORP/4381568/REV B/OP 1\n"
"OSHKOSH/12611249/REV A/OP1\n"
"14A1669 COVER-REV-J\n"
"OSH 4641290\n"
"KCC C318-M-2372\n"
"2328 FINISH\n"
"10751755-REV-2\n"
"312-133001-001-REV-D\n"
"KOOTR KT300AL OP1\n"
"OSHKOSH CORP/4381568/REV B/OP 2\n"
"360 YIELD 450201 LH MAIN PROGRAM;360 YIELD 450201 RH MAIN PROGRAM;450201\n"
"OSH 3899580OP2\n"
"10520398ITEM17\n"
"WELD30BIG\n"
"2347337-01-REV-NONE\n"
"2372 FINISH\n"
"10753199-02-REV-7\n"
"OSH 1693510\n"
"2328END\n"
"OSH 4384499OP2\n"
"E4-TKD-Z002A00KP;E4-TKD-ZOO2AOO WITH TRANSFER\n"
"10753199-02-REV-6\n"
"OSH 4384499\n"
"7494-04-103-REV-NONE\n"
"14A1669D2F1-REV-J\n"
"4212.8801-REV-O\n"
"2373 FINISH\n"
"2372 TAPER\n"
"SHARPE-36465 2ND\n"
"KOOTR KT300AL OP2\n"
"312-133034-001-REV-B\n"
"14A1937-REV-01\n"
"OSHKOSH/12611249/REV A/OP2\n"
"SANTASISE398FOP3\n"
"SIEMENS10248226REV08\n")
matches = re.finditer(regex, test_str, re.MULTILINE)
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