const regex = /^[^\:]+\:(?<field1>[^\|]*)\|(?<field2>[^\|]*)\|(?<field3>[^\|]*)\|(?<field4>[^\|]*)\|(?<field5>[^\|]*)\|(?<field6>[^\|]*)\|(?<field7>[^\|]*)\|(?<field8>[^\|]*)\|(?<field9>[^\|]*)\|(?<field10>[^\|]*)\|(?<field11>[^\|]*)\|(?<field12>[^\|]*)\|(?<field13>[^\|]*)/;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^[^\\:]+\\:(?<field1>[^\\|]*)\\|(?<field2>[^\\|]*)\\|(?<field3>[^\\|]*)\\|(?<field4>[^\\|]*)\\|(?<field5>[^\\|]*)\\|(?<field6>[^\\|]*)\\|(?<field7>[^\\|]*)\\|(?<field8>[^\\|]*)\\|(?<field9>[^\\|]*)\\|(?<field10>[^\\|]*)\\|(?<field11>[^\\|]*)\\|(?<field12>[^\\|]*)\\|(?<field13>[^\\|]*)', '')
const str = `- Promotion Created, Coupon Settings For PromoCode=121509PromoId=3550966 : 17429150|Gillette|111082|9999999|Save \$5.00 on Gillette|Save \$5.00 on ONE Gillette Fusion ProShield|2016-05-29T07:00:00Z|2016-07-02T07:00:00Z|2016-07-02T07:00:00Z||811000474001215093500110100|RMS|[047400656048, 047400656055, 047400656062, 047400656079, 047400656109, 047400656116]|[]||RetailerBanners : [Brookshire]`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
if ((m = regex.exec(str)) !== null) {
// 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