const regex = /(?ms)<PNR>([\w]+)<\/PNR>
/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?ms)<PNR>([\\w]+)<\\\/PNR>
', 'g')
const str = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<EGE_Booking>
<TripID>1004-3637-360</TripID>
<RecordLocator>1004-3637-360</RecordLocator>
<Travelers>
<Traveler>
<PerCode>13593199</PerCode>
<FirstName>Claude</FirstName>
<LastName>Christensson</LastName>
<ContactDetails>
<Email>claude.christensson@wirelesscar.com</Email>
<MobilePhone>46765537005</MobilePhone>
</ContactDetails>
<TravellerCostCenter>
<CostCenter Code="CC3">
<Label>Employee ID</Label>
<Value>56524</Value>
</CostCenter>
<CostCenter Code="CC4">
<Label>Global Department code</Label>
<Value>DI43400</Value>
</CostCenter>
</TravellerCostCenter>
</Traveler>
</Travelers>
<Segments>
<HotelSegment>
<HOTEL>
<TripItemID>5a7dc8f971ac0163f7563e7e</TripItemID>
<PNR>ABC1DS</PNR>
<Status>V</Status>
<CheckInDate>2018-02-13</CheckInDate>
<CheckOutDate>2018-02-14</CheckOutDate>
<Vendor SupplierType="11281422">Genting Hotel</Vendor>
<PropertyName>Genting Hotel</PropertyName>
<Location>
<Name>Pendigo Way, England, B40 1PU</Name>
<City>Birmingham</City>
<Country Code="GBR">Storbritannien</Country>
</Location>
<ConfirmationCode>982674693</ConfirmationCode>
<Cost>
<Amount>751.08</Amount>
<Currency Code="SEK">Swedish Krona</Currency>
</Cost>
<OutOfPolicyReasons/>
</HOTEL>
<HOTEL>
<TripItemID>5a7dc8f971ac0163f7563e7e</TripItemID>
<PNR>55545261643</PNR>
<Status>V</Status>
<CheckInDate>2018-02-13</CheckInDate>
<CheckOutDate>2018-02-14</CheckOutDate>
<Vendor SupplierType="11281422">Genting Hotel</Vendor>
<PropertyName>Genting Hotel</PropertyName>
<Location>
<Name>Pendigo Way, England, B40 1PU</Name>
<City>Birmingham</City>
<Country Code="GBR">Storbritannien</Country>
</Location>
<ConfirmationCode>982674693</ConfirmationCode>
<Cost>
<Amount>751.08</Amount>
<Currency Code="SEK">Swedish Krona</Currency>
</Cost>
<OutOfPolicyReasons/>
</HOTEL>
</HotelSegment>
</Segments>
<Invoicing>
<CompanyCode>28781</CompanyCode>
<ClientNumber>28781</ClientNumber>
<ClientRequisition>claude.christensson@wirelesscar.com</ClientRequisition>
<ClientReference>689100277</ClientReference>
<ClientCostCenter>
<CostCenter Code="CC1">
<Label>Legal Entity</Label>
<Value>WirelessCar Sweden AB</Value>
</CostCenter>
<CostCenter Code="CC2">
<Label>Cost Center</Label>
<Value>989502</Value>
</CostCenter>
</ClientCostCenter>
</Invoicing>
</EGE_Booking>
`;
// 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