# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"\b(Sydney|Melbourne|Brisbane|Adelaide)\b\s[\W\s\r]{0,10}[0-9]{4}\,\s(?<TimeIB>[0-9:APM]{6,7})[\W\s\r]{1,5}[\W\s\rA-Za-z0-9]{5,180}Payment|\b(Sydney|Melbourne|Brisbane|Adelaide)\b\sSUBSIDIARY\/FRANCHISE[\W\s\r]{0,10}[0-9]{4}\,\s(?<TimeIB2>[0-9:APM]{6,7})[\W\s\r]{1,5}[\W\s\rA-Za-z0-9]{5,180}Payment"
test_str = ("E-Ticket Itinerary, Receipt and Tax Invoice\n\n"
"Your Booking Reference\n\n"
"OML4CW\n"
"Important Information\n"
"• This is your E-Ticket Itinerary & Receipt/Tax Invoice. We recommend that you print this out or save this on your phone, and it\n"
"is recommended you retain a copy for your records.\n"
"• Each passenger travelling needs a printed copy of this document for airport security checks.\n"
"• Please familiarise yourself with the key Conditions of Carriage, Dangerous Goods guide and other information attached.\n"
"Passenger Ticket Information\n"
"Passenger Name\n\n"
"Frequent Flyer No.\n\n"
"Ticket No.\n\n"
"Issued\n\n"
"Mr Matthew Davis\n\n"
"QF1911660387\n"
"Frequent Flyer Silver / oneworld Ruby\n\n"
"081-2498583545\n\n"
"30 Aug 19\n\n"
"Ticket Total*\n"
"423.32\n\n"
"Mr Zachary Kirkham\n\n"
"QF1752890\n"
"Qantas Club Silver / oneworld Ruby\n\n"
"081-2498583544\n\n"
"30 Aug 19\n\n"
"423.32\n\n"
"Ticket Total for all passengers*\n\n"
"846.64\n\n"
"*Amounts are displayed in AUD (AUD)\n\n"
"Your Itinerary\n"
"Date\n\n"
"Flight Number\n\n"
"Departing\n\n"
"Arriving\n\n"
"Status\n\n"
"Flight Information\n\n"
"08 Sep 19\n\n"
"QF435\n\n"
"Sydney\n"
"1300, 1:00PM\n"
"Terminal 3\n\n"
"Melbourne\n"
"1435, 2:35PM\n"
"08 Sep 19\n"
"Terminal 1\n\n"
"Economy\n"
"Confirmed\n\n"
"Est journey Time: 01:35\n"
"Non-Stop\n"
"Aircraft Type: Boeing 737\n\n"
"08 Sep 19\n\n"
"QF2285 Operated By\n"
"Melbourne\n"
"SUBSIDIARY/FRANCHISE 1520, 3:20PM\n"
"Terminal 1\n\n"
"Launceston\n"
"1635, 4:35PM\n"
"08 Sep 19\n\n"
"Economy\n"
"Confirmed\n\n"
"Est journey Time: 01:15\n"
"Non-Stop\n"
"Aircraft Type: De Havilland Dhc-8 Dash\n"
"8-400 Dash 8q\n\n"
"Payment Details\n"
"Date\n\n"
"Payment Type\n\n"
"Reference\n\n"
"30 Aug 19\n\n"
"American Express\n\n"
"xxxx-xxxx-xxxx-2006\n\n"
"Amount*\n"
"846.64\n\n"
"This may appear as multiple transactions on your credit card statement\n\n"
"Your Receipt Details\n"
"Ticket Charges\n"
"Total*\n"
"Card Payment Fee\n\n"
"Total Amount Payable*\n\n"
"Charges\n"
"761.68\n"
"8.00\n\n"
"GST\n\n"
"Total*\n\n"
"769.68\n\n"
"76.96\n\n"
"846.64\n\n"
"*Includes Taxes/Fees/carrier Charges\n\n"
"Tax Information\n"
"GST is included for taxable sales\n"
"ABN:58084409316\n\n"
"Issued by\n"
"Qantas Airways on 30 Aug 19\n\n"
"GST Paid 76.96\n\n"
"Flying With Us\n"
"Before Check-in\n"
"• Ensure that each passenger\n"
"carries a printed copy of this\n"
"document when travelling.\n"
"• Label your bags inside and out\n"
"with your name, address and\n"
"contact number at your\n"
"destination.\n"
"• Check Carry-on baggage and\n"
"checked baggage allowances as\n"
"restrictions apply.\n\n"
"Getting Away On Time\n"
"• Ensure you are at the airport with\n"
"enough time to complete necessary\n"
"check-in, security screening and,\n"
"for international flights, customs\n"
"and immigration.\n"
"• Familiarise yourself with the checkin and boarding times. Information\n"
"for Qantas and QantasLink flights is\n"
"in the Travel Information section\n"
"attached.\n\n"
"Check-in\n"
"• Visit qantas.com/checkin to\n"
"choose the check-in option best\n"
"for you.\n\n"
"Fare Restrictions - Refer to the applicable fare rules as special conditions may apply\n"
"Additional Fees: Fees may apply to some booking changes, ticket reissues and consultant-assisted services. Details are available at qantas.com.\n\n"
"Qantas Airways Limited ABN 16 009 661 901, 10 Bourke Road, Mascot NSW 2020, Australia\n"
"qantas.com\n\n"
"Travel Information\n"
"Qantas Group check-in times\n\n"
"International Terminal\n\n"
"Domestic Terminal\n\n"
"Australian and New Zealand Terminals**\n\n"
"QF 001 - 399\n\n"
"QF400 and above\n\n"
"International First / Business\n"
"International Economy / Premium Economy\n\n"
"Closes 60 minutes before departure\n"
"Closes 90 minutes before departure\n\n"
"Domestic Business / Economy\n\n"
"Closes 60 minutes before departure\n\n"
"Qantas codeshare services (QF Flight\n"
"numbers operated by Jetstar)^\n"
"Jetstar Services^\n\n"
"Check in opens 3 hours before departure\n"
"Closes 60 minutes before departure\n"
"JQ 001 - 399 and 3K 500 - 699^\n\n"
"N/A\n"
"N/A\n"
"45 minutes from departure* Closes 30\n"
"minutes before departure.\n"
"Check in opens 2 hours before departure\n"
"Closes 30 minutes before departure\n"
"JQ 400 and above\n\n"
"Jetstar Business / Economy (JQ)^\n\n"
"Check in opens 3 hours before departure\n"
"Closes 60 minutes before departure\n"
"Check in opens 2 hours before departure\n\n"
"Check in opens 2 hours before departure\n"
"Closes 30 minutes before departure\n"
"N/A\n\n"
"Jetstar flights operated by Jetstar Asia (3K)~\n\n"
"* Check-in closes 30 minutes before departure. Boarding will commence 20 minutes prior to departure. ** Please check with your local Qantas office for check-in\n"
"time at all non-Australian / New Zealand ports. Ensure you adhere to check-in times or your fare may be forfeited.\n"
"^ Jetstar flights JQ1-JQ399 depart from international terminals, except JQ61, JQ73 and JQ81 which depart from domestic terminals.\n"
"~ Jetstar flights that operate under a 3K flight number between Perth and Singapore and Singapore and Auckland check-in opens 3 hours prior to departure and\n"
"closes 1 hour prior to departure.\n\n"
"Included and Carry On Baggage\n\n"
"QF435\n\n"
"Sydney to Melbourne - 08 Sep 2019\n"
"PASSENGER\n\n"
"Mr Matthew Davis\n\n"
"INCLUDED CHECKED BAGGAGE\n"
"(no single piece may exceed 32kg / 67lb)\n\n"
"PURCHASED BAGGAGE\n"
"(no single piece may exceed 32kg / 67lb)\n\n"
"CARRY ON BAGGAGE\n"
"(Up to 10kg(22lb) for one piece, max 14kg(30lb) total)\n\n"
"1 x 32kg/70lb\n\n"
"-\n\n"
"Cabin bag combination + 1 personal item\n\n"
"1 x 32kg/70lb\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