# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"BCF-(\d+)\s+([\w]+)[A-Z\s\d\-]+(?:BTS-\d+[\sA-Z-]+\d+\s+\d+\s+)([A-Z]+)"
test_str = ("BCF-1522 FLEXI EDGE U WO 4 B1522 WO\n"
" 01137 22186 BTS-1522 U WO 1 0\n"
" CALLEORIN6 RF/-\n"
" 23\n"
" TRX-001 U WO 673 0 1787 MBCCH P 10\n"
" TRX-002 U WO 681 0 1787 9\n"
" TRX-003 U WO 663 0 1787 8\n"
" TRX-004 U WO 659 0 1787 6\n"
" 01137 22187 BTS-1523 U WO 0 1\n"
" CALLEORIN7 RF/-\n"
" 24\n"
" TRX-005 U WO 675 0 320 MBCCH P 8\n"
" TRX-006 U WO 657 0 320 10\n"
" TRX-007 U WO 665 0 320 4\n"
" TRX-008 U WO 638 0 320 0\n"
" 01137 22188 BTS-1524 U WO 0 0\n"
" CALLEORIN8 RF/-\n"
" 16\n"
" TRX-009 U WO 651 0 1729 MBCCH P 7\n"
" TRX-010 U WO 643 0 1729 4\n"
" TRX-011 U WO 648 0 1729 7\n\n"
"BCF-1526 ULTRASITE U BL-BCF 7 B1526 WO\n"
" 01134 01186 BTS-1526 U BL-BCF 0 0\n"
" LDANIELAS6 RF/-\n"
" 0\n"
" EDGE TRX-001 U BL-BCF 672 0 1736 MBCCH P 2\n"
" EDGE TRX-002 U BL-BCF 674 0 1736 0\n"
" EDGE TRX-003 U BL-BCF 657 0 1737 5\n"
" EDGE TRX-004 U BL-BCF 648 0 1737 6\n"
" 01134 01187 BTS-1527 U BL-BCF 0 0\n"
" LDANIELAS7 RF/-\n"
" 0\n"
" EDGE TRX-005 U BL-BCF 645 0 1736 2\n"
" EDGE TRX-006 U BL-BCF 639 0 1736 0\n"
" EDGE TRX-007 U BL-BCF 683 0 1736 MBCCH P 5\n"
" EDGE TRX-008 U BL-BCF 641 0 1736 6\n"
" 01134 01188 BTS-1528 U BL-BCF 0 0\n"
" LDANIELAS8 RF/-\n"
" 0\n"
" EDGE TRX-009 U BL-BCF 662 0 1737 MBCCH P 7\n"
" EDGE TRX-010 U BL-BCF 643 0 1737 2\n"
" EDGE TRX-011 U BL-BCF 652 0 1737 0\n"
" EDGE TRX-012 U BL-BCF 664 0 1737 5\n\n"
"BCF-1540 ULTRASITE L BL-USR 3 B1540 BL\n"
" 01134 12543 BTS-0055 L BL-USR 0 0\n"
" SANTAINES3 RF/-\n"
" 0\n"
" EDGE TRX-001 U BL-USR 128 0 1773 MBCCH P 9\n"
" EDGE TRX-003 U BL-USR 145 0 1773 10\n"
" EDGE TRX-004 U BL-USR 237 0 1773 4\n"
" EDGE TRX-005 U BL-USR 155 0 1773 2\n"
" EDGE TRX-006 U BL-USR 233 0 1773 9\n"
" EDGE TRX-007 U BL-USR 150 0 1773 10\n"
" 01134 12548 BTS-0057 L BL-USR 0 0\n"
" SANTAINES8 RF/-\n"
" 0\n"
" EDGE TRX-008 U BL-USR 669 0 1361 MBCCH P 6\n"
" EDGE TRX-010 U BL-USR 643 0 1361 4\n"
" EDGE TRX-011 U BL-USR 683 0 1361 2\n"
" EDGE TRX-012 U BL-USR 664 0 1361 9\n\n"
"BCF-1543 ULTRASITE U WO 6 B1543 WO\n"
" 01137 12822 BTS-0206 U WO 0 0\n"
" VERACRUZ2 RF/-\n"
" 0\n"
" EDGE TRX-001 U WO 137 0 1771 MBCCH P 10\n"
" EDGE TRX-002 U BL-RSL 128 0 1771 8\n"
" EDGE TRX-003 U WO 139 0 1771 10\n"
" 01137 12828 BTS-0717 U WO 1 0\n"
" VERACRUZ8 RF/-\n"
" 8\n"
" EDGE TRX-005 U WO 678 0 1735 MBCCH P 0\n"
" EDGE TRX-007 U BL-RSL 655 0 1735 3\n"
" EDGE TRX-008 U WO 649 0 1735 6\n"
" EDGE TRX-009 U BL-RSL 657 0 1735 3\n\n"
"BCF-1615 ULTRASITE U WO 2 B1615 WO\n"
" 01139 10012 BTS-0086 L BL-USR 0 0\n"
" ADRIATICA2 RF/-\n"
" 0\n"
" EDGE TRX-001 U BL-USR 135 0 1366 MBCCH P 10\n"
" EDGE TRX-003 U BL-USR 133 0 1366 10\n"
" EDGE TRX-004 U BL-USR 147 0 1366 9\n"
" EDGE TRX-005 U BL-USR 153 0 1682 10\n"
" EDGE TRX-006 U BL-USR 155 0 1682 4\n\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