const regex = /(?:\/p\/|$)(?:[^\/]*)(?<=-)(.*)(?=\/)/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?:\\\/p\\\/|$)(?:[^\\\/]*)(?<=-)(.*)(?=\\\/)', 'g')
const str = `https://www.ikea.com/de/de/p/hallbar-abfalltrennungsloesung-mit-auszug-hellgrau-s09308825/
https://www.ikea.com/de/de/p/symfonisk-regal-wifi-speaker-schwarz-50357554/?tduid=d8b332c221610a36288c647f8959959f&utm_medium=affiliate&utm_name=generic&utm_term=conversion&utm_content=deeplink&utm_source=SmartApfel
https://www.ikea.com/de/de/p/symfonisk-tischleuchte-mit-wifi-speaker-weiss-30435157/?tduid=d8b332c221610a36288c647f8959959f&utm_medium=affiliate&utm_name=generic&utm_term=conversion&utm_content=deeplink&utm_source=SmartApfel
https://www.ikea.com/de/de/p/tradfri-gateway-weiss-40337806/?tduid=d8b332c221610a36288c647f8959959f&utm_content=feed&utm_medium=affiliate&utm_name=generic&utm_source=SmartApfel&utm_term=conversion
https://www.ikea.com/de/de/p/fyrtur-verdunklungsrollo-kabellos-batteriebetrieben-grau-40408196/?tduid=d8b332c221610a36288c647f8959959f&utm_content=feed&utm_medium=affiliate&utm_name=generic&utm_source=SmartApfel&utm_term=conversion
https://www.ikea.com/de/de/p/kadrilj-rollo-kabellos-batteriebetrieben-grau-90408127/?tduid=d8b332c221610a36288c647f8959959f&utm_content=feed&utm_medium=affiliate&utm_name=generic&utm_source=SmartApfel&utm_term=conversion`;
// 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