const regex = /TST(?'TQTId'\d{5})|[ \d]{2}\d\.FV.*(?'IssuingAirline'\w\w)|FARE (?'FarePricingIndicator'.) (?'FareCurrency'...)(?'Fare'.{11})|GRAND TOTAL (?'GTCurrency'...)(?'GrandTotal'.{11})|(?'Seg'[ \d]\d . (?'Origin'\w\w\w) (?'Carrier'..) (?'FlightNo'....) (?'Class'.).(?'DepDate'\d\d\w\w\w).(?'DepTime'\d\d\d\d) (?'Status'...) (?'FareBasis'.{8}) (.{18})(?'BgAllowance'...))|^ (?'Destination'\w\w\w).*$|^.*$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('TST(?\'TQTId\'\\d{5})|[ \\d]{2}\\d\\.FV.*(?\'IssuingAirline\'\\w\\w)|FARE (?\'FarePricingIndicator\'.) (?\'FareCurrency\'...)(?\'Fare\'.{11})|GRAND TOTAL (?\'GTCurrency\'...)(?\'GrandTotal\'.{11})|(?\'Seg\'[ \\d]\\d . (?\'Origin\'\\w\\w\\w) (?\'Carrier\'..) (?\'FlightNo\'....) (?\'Class\'.).(?\'DepDate\'\\d\\d\\w\\w\\w).(?\'DepTime\'\\d\\d\\d\\d) (?\'Status\'...) (?\'FareBasis\'.{8}) (.{18})(?\'BgAllowance\'...))|^ (?\'Destination\'\\w\\w\\w).*$|^.*$', 'gm')
const str = `TST00002 ATHG42100 CN/02MAY I 0 LD 24SEP23 2359 OD MNLBRE
T-
FXP
1.ABAYARE/ROMEO DACER MR(ID7833)
2.SEBASTIAN/JAY AR SIMON MR(ID47129)
1 MNL TK 085 Y 24SEP 2125 OK YFOW 30K
2 X IST TK 1331 Y 25SEP 0720 OK YFOW 30K
BRE
FARE F USD 2000.00
EQUIV EUR 1810.00
TX001 X EUR 193.60-YRVA TX002 X EUR 8.95-LIDC TX003 X EUR 1.50-M6SE
TX004 X EUR 5.00-TRAE TX005 X EUR 0.85-RAAD
TOTAL EUR 2019.90 BSR 0.90463353
GRAND TOTAL EUR 2019.90
MNL TK X/IST TK BRE2000.00NUC2000.00END ROE1.000000
18.FE NONEND/TK ONLY
19.FM *F*0.00
20.FP INV
21.FV TK`;
// 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