const regex = /[^\/]*(?=\.html)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('[^\\\/]*(?=\\.html)', 'gm')
const str = `https://www.sample.com/avantco-178gskt19824-door-gasket-for-gdc-12f-and-gdc-12f-hc-merchandiser-freezers/178GSKT19824.html?utm_source=google&utm_medium=cpc&utm_campaign=GoogleShopping`;
// 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