# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"^----\n(Airport\s+TNCB.*(?:\n.*)*?)\n----"
test_str = ("----\n"
"Airport SPQU :S16:20:25.6431 W071:34:22.3800 8338ft\n"
"Country Name=\"Peru\"\n"
"State Name=\"\"\n"
"City Name=\"Arequipa\"\n"
"Airport Name=\"Rodriguez Ballon\"\n"
"in file: ORBX\\FTX_VECTOR\\FTX_VECTOR_AEC\\scenery\\AEC_SPQU.bgl\n"
"----\n"
"Airport SPRF :S14:15:59.9484 W070:27:59.9997 14419ft\n"
"Country Name=\"Peru\"\n"
"State Name=\"\"\n"
"City Name=\"San Rafael\"\n"
"Airport Name=\"San Rafael\"\n"
"in file: Scenery\\0304\\scenery\\APX29370.bgl\n"
"Start 12 : S14:15:40.9653 W070:28:38.3900 14419ft Hdg: 117.0T, Length 8760ft \n"
"Start 30 : S14:16:18.9314 W070:27:21.6092 14419ft Hdg: 297.0T, Length 8760ft \n"
"0120 Lat -14.261198 Long -70.477715 Alt 14419 Hdg 120 Len 8760 Wid 98\n"
"0300 Lat -14.272106 Long -70.455620 Alt 14419 Hdg 300 Len 8760 Wid 98\n"
"----\n"
"Airport TNCB :N12:08:25.5567 W068:16:34.3503 20ft\n"
"Country Name=\"Netherlands Antilles\"\n"
"State Name=\"\"\n"
"City Name=\"Bonaire I\"\n"
"Airport Name=\"Flamingo\"\n"
"in file: Scenery\\0303\\scenery\\APX29270.bgl\n"
"Start 10 : N12:08:23.2891 W068:17:16.0525 20ft Hdg: 92.0T, Length 9448ft \n"
"Start 28 : N12:08:20.1144 W068:15:43.9767 20ft Hdg: 272.0T, Length 9448ft \n"
"0100 Lat 12.139818 Long -68.288246 Alt 20 Hdg 100 Len 9448 Wid 148\n"
"0280 Lat 12.138905 Long -68.261757 Alt 20 Hdg 280 Len 9448 Wid 148\n"
"----\n"
"Airport TNCC :N12:11:20.0649 W068:57:34.8897 29ft\n"
"Country Name=\"Netherlands Antilles\"\n"
"State Name=\"\"\n"
"City Name=\"Curacao I\"\n"
"Airport Name=\"Willemstad-Hato Intl.\"\n"
"in file: Scenery\\0303\\scenery\\APX29270.bgl\n"
"Start 11 : N12:11:30.5607 W068:58:24.9607 29ft Hdg: 102.1T, Length 11186ft \n"
"Start 29 : N12:11:08.2410 W068:56:38.2654 29ft Hdg: 282.1T, Length 11186ft \n"
"0110 Lat 12.191923 Long -68.974129 Alt 29 Hdg 111 Len 11186 Wid 197 ILS 111.90, Flags: GS DME BC\n"
"0290 Lat 12.185513 Long -68.943428 Alt 29 Hdg 291 Len 11186 Wid 197\n"
"----\n"
"Airport TNCE :N17:29:32.4738 W062:58:29.8992 129ft\n"
"Country Name=\"Netherlands Antilles\"\n"
"State Name=\"\"\n"
"City Name=\"St Eustatius I\"\n"
"Airport Name=\"F.D. Roosevelt\"\n"
"in file: ORBX\\FTX_OLC\\FTX_VECTOR_FixedAPT\\scenery\\APT_TNCE.BGL\n"
"Start 6 : N17:29:35.1949 W062:59:02.6666 129ft Hdg: 50.3T, Length 4268ft \n"
"Start 24 : N17:30:00.9808 W062:58:30.1439 129ft Hdg: 230.2T, Length 4268ft \n"
"0060 Lat 17.492956 Long -62.984272 Alt 129 Hdg 63 Len 4268 Wid 98\n"
"0240 Lat 17.500425 Long -62.974819 Alt 129 Hdg 243 Len 4268 Wid 98\n"
"----\n"
"Airport TNCM :N18:02:27.0378 W063:06:34.2595 13ft\n"
"Country Name=\"Netherlands Antilles\"\n"
"State Name=\"\"\n"
"City Name=\"St Maarten I\"\n"
"Airport Name=\"Princess Juliana Intl\"\n"
"in file: Scenery\\0303\\scenery\\APX31250.bgl\n"
"Start 9 : N18:02:21.9843 W063:07:08.8215 13ft Hdg: 81.7T, Length 7150ft \n"
"Start 27 : N18:02:31.8322 W063:05:57.8823 13ft Hdg: 261.7T, Length 7150ft \n"
"0090 Lat 18.039392 Long -63.119469 Alt 13 Hdg 95 Len 7150 Wid 148\n"
"0270 Lat 18.042223 Long -63.099060 Alt 13 Hdg 275 Len 7150 Wid 148\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