Skip to content

Instantly share code, notes, and snippets.

@eightyknots
Last active July 7, 2024 20:19
Show Gist options
  • Save eightyknots/4372d1166a192d5e9754 to your computer and use it in GitHub Desktop.
Save eightyknots/4372d1166a192d5e9754 to your computer and use it in GitHub Desktop.
AvReg: Aviation regex match toolkit

AvReg: The Aviation RegEx Match Toolkit

General Tips

  • The PCRE flavour of RegEx is used here.
  • Append the i modifier to the end of the regex to make any pattern case-insensitive.

Aircraft

Purpose Description RegEx Example
Registration National registration /^[A-Z]-[A-Z]{4}|[A-Z]{2}-[A-Z]{3}|N[0-9]{1,5}[A-Z]{0,2}$/ N390HA
IATA aircraft type 3-character type code /^[A-Z0-9]{3}$/ 32N
ICAO aircraft type (Typically) 4-character type code /^[A-Z]{1}[A-Z0-9]{1,3}$/ A32N

Airline Codes

Purpose Description RegEx Example
IATA code Commercial service mark /^[A-Z][\d]|[\d][A-Z]|[A-Z]{2}$/ CX
ICAO code Operational service mark /^[A-Z]{3}$/ CPA
Ticketing prefix eTicket operator code /^[0-9]{3}$/ 160

Airport Codes

Purpose Description RegEx Example
IATA code Commercial service mark /^[A-Z]{3}$/ LHR
ICAO code Operational service mark /^[A-Z]{4}$/ EGLL
FAA code US FAA-specific locator /^[A-Z0-9]{3,4}$/ L67

Air Navigation & Communication

Notes:

  • Privately-owned Canadian NDBs may utilize a letter and number combination.
  • VFR squawk codes are generally 1200 in North America and 7000 in Europe.
Purpose Description RegEx Example
NDB Non-directional beacon identifier /^[A-Z]{1,3}$/ TD
VOR VHF omnidirectional range ident /^[A-Z]{3}$/ APU
INT Airway intersection waypoint /^[A-Z]{5}$/ PRAWN
Squawk Code Unique transponder octal code /^[0-7]{4}$/ 0318
Distress If match, aircraft is in distress /^7[567]00$/ 7700
VFR Squawk XPDR code for aircraft under VFR /^(1200)|(7000)$/ 1200
Runways Standard runway identifiers 01-36 /^(0?[1-9]|[1-2]\d|3[0-6])[LCR]?$/ 36L

Ticketing & Business Operations

Note that for PNR record identifiers, some GDS providers and operators use 5-character PNR idents, but most use 6-character ones. Additionally, for readibility purposes, some airlines and systems will skip 0, 1, I, L, and O.

Purpose Description RegEx Example
PNR identifier Passenger record locator /^[A-Z0-9]{5,6}$/ J5XTP2
E-ticket number Ticketing and itinerary identifier /^[0-9]{3}(-)?[0-9]{10}$/ 160-4837291830

Flight Operations

Purpose Description RegEx Example
Flight number IATA (marketing) flight number /^([A-Z][\d]|[\d][A-Z]|[A-Z]{2})(\d{1,})$/ BA026
Callsign ICAO (operational) flight number /^[A-Z]{3}[A-Z0-9]{1,}$/ BAW319K
@eightyknots
Copy link
Author

@mtowers - Thank you, I've updated the FAA identifiers per your suggestion with the exception of using $^ tokens instead of word boundaries. This is just to keep everything else in line.

@Tricky-D & @obotor - Thanks for your inputs as well. I will review & make update shortly on registration numbers. It may come down to splitting US since we can be more specific with FAA registrations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment