const regex = /gsScrollPos=(.*?);|gsScrollPos=(.*)/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('gsScrollPos=(.*?);|gsScrollPos=(.*)', 'g')
const str = `_jsuid=1540521894; new=verified; __insp_slim=1441894084306; __insp_wid=1141935839; __insp_nv=true; __insp_ref=d; __insp_targlpu=http%3A%2F%2Flocalhost%2F; __insp_norec_sess=true; aff_tag=55b88a; aff_from=; aff_time=1441896839; gsScrollPos=; _gat=1; _ga=GA1.1.1421736560.1435009203`;
// 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