const regex = /Booking Voucher Number: (?<number>\d\d\d\d\d\d\d\d\d\d)|(Guest Name : (?<name>\w\w.*))|(Check In Date : (?<date>\d{4}-\d{2}-\d{2}))|(Check Out Date : (?<Outdate>\d{4}-\d{2}-\d{2}))|(Number of Rooms : (?<RoomNumbers>)\d.*)|(Special Request : (?<SRQST>\w.*))|(paid for Guests: (?<PfG>)\d.*)|(Room Type : (?<RoomType>)\w.*)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('Booking Voucher Number: (?<number>\\d\\d\\d\\d\\d\\d\\d\\d\\d\\d)|(Guest Name : (?<name>\\w\\w.*))|(Check In Date : (?<date>\\d{4}-\\d{2}-\\d{2}))|(Check Out Date : (?<Outdate>\\d{4}-\\d{2}-\\d{2}))|(Number of Rooms : (?<RoomNumbers>)\\d.*)|(Special Request : (?<SRQST>\\w.*))|(paid for Guests: (?<PfG>)\\d.*)|(Room Type : (?<RoomType>)\\w.*)', 'gm')
const str = `Booking Voucher Number: 2052892268
Guest Name : Maxie Dibbert
Check In Date : 2018-11-09
Check Out Date : 2018-11-10
Number of Rooms : 14
Booking Type : Pay At Hotel Amount To Be Collected : 91.2 (SOD)
Special Request : NA
Breakfast Included: No Breakfast
paid for Guests: 0
Room Type : Single Bed in Female Dormitory
`;
// 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