const regex = /(?:^|,)([A-Za-z\-]+?)(?::[A-Z\-]+)?=(".+?"|\d+?)(?=,|$)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?:^|,)([A-Za-z\\-]+?)(?::[A-Z\\-]+)?=(".+?"|\\d+?)(?=,|$)', 'gm')
const str = `EXT-X-DATERANGE:ID="PreRoll_Ident_Open",START-DATE="2016-12-14T120000.000z",DURATION=3,X-PlayHeadStart="0.000",X-AdID="AA-1QPN49M9H2112",X-TRANSACTION-VPRN-ID="1486060788",X-TrackingDefault="1",X-TrackingDefaultURI="http,//606ca.v.fwmrm.net/ad/l/1?s=g015&n=394953%3B394953&t=1485791181366184015&f=&r=394953&adid=15914070&reid=5469372&arid=0&auid=&cn=defaultImpression&et=i&_cc=15914070,5469372,,,1485791181,1&tpos=0&iw=&uxnw=394953&uxss=sg579054&uxct=4&metr=1031&init=1&vcid2=394953%3A466c5842-0cce-4a16-9f8b-a428e479b875&cr="s=0&iw=&uxnw=394953&uxss=sg579054&uxct=4&metr=1031&init=1&vcid2=394953%3A466c5842-0cce-4a16-9f8b-a428e479b875&cr="`;
// 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