const regex = /^(?<FlightDesignator>([A-Z0-9]{2}[A-Z]?)([0-9]{3,4}))(?<OperationalSuffix>[A-Z])?(?<FlightIdentifierDate>\/(\d{2})([A-Z]{3})?(\d{2})?)?(\s(?<FlightLegsChangeIdentifier>(\/?[A-Z]{3})+)(?=(\s|$)))?(\s1(?<JointOperationAirlineDesignators>(\/.{2}[A-Z]?)+))?(\s3\/(?<AircraftOwner>([A-Z]{2}|.)))?(\s4\/(?<CockpitCrewEmployer>(.+?)(?=(?: \d\/|$))))?(\s5\/(?<CabinCrewEmployer>([A-Z]{2}|.)))?(?<OnwardFlight>\s6\/(([A-Z0-9]{2}[A-Z]?)([0-9]{3,4}))([A-Z])?(\/(\d{2})([A-Z]{3})?(\d{2})?)?)?(\s7\/(?<MealServiceNote>(\/?[A-Z]{0,3})+))?(\s9\/(?<OperatingAirlineDisclosure>(.{2}[A-Z]?)))?/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(?<FlightDesignator>([A-Z0-9]{2}[A-Z]?)([0-9]{3,4}))(?<OperationalSuffix>[A-Z])?(?<FlightIdentifierDate>\\\/(\\d{2})([A-Z]{3})?(\\d{2})?)?(\\s(?<FlightLegsChangeIdentifier>(\\\/?[A-Z]{3})+)(?=(\\s|$)))?(\\s1(?<JointOperationAirlineDesignators>(\\\/.{2}[A-Z]?)+))?(\\s3\\\/(?<AircraftOwner>([A-Z]{2}|.)))?(\\s4\\\/(?<CockpitCrewEmployer>(.+?)(?=(?: \\d\\\/|$))))?(\\s5\\\/(?<CabinCrewEmployer>([A-Z]{2}|.)))?(?<OnwardFlight>\\s6\\\/(([A-Z0-9]{2}[A-Z]?)([0-9]{3,4}))([A-Z])?(\\\/(\\d{2})([A-Z]{3})?(\\d{2})?)?)?(\\s7\\\/(?<MealServiceNote>(\\\/?[A-Z]{0,3})+))?(\\s9\\\/(?<OperatingAirlineDisclosure>(.{2}[A-Z]?)))?', 'gm')
const str = `BNE1010/1000 HKG1955/2005 7/PLD/CLD/YLD
RG878A/21AUG15 GIG/BOG 1/RG/AV 3/AV 4/AV 5/RG 6/AV081C/22 7/CDC/YD 9/TP`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions