const regex = /href="(?<href>.*?)"|src="(?<imgsrc>.*?)"/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('href="(?<href>.*?)"|src="(?<imgsrc>.*?)"', 'g')
const str = `<a rel="nofollow" href="http://www.amazon.de/gp/product/B004DI7A5S/ref=as_li_tl?ie=UTF8&camp=1638&creative=6742&creativeASIN=B004DI7A5S&linkCode=as2&tag=webbigode-21">PFIFF Reitstrumpf kariert, grau/lila, 37-39, 100322-144-37</a><img src="http://ir-de.amazon-adsystem.com/e/ir?t=webbigode-21&l=as2&o=3&a=B004DI7A5S" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
<a rel="nofollow" href="http://www.amazon.de/gp/product/B004DI7A5S/ref=as_li_tl?ie=UTF8&camp=1638&creative=6742&creativeASIN=B004DI7A5S&linkCode=as2&tag=webbigode-21"><img border="0" src="http://ws-eu.amazon-adsystem.com/widgets/q?_encoding=UTF8&ASIN=B004DI7A5S&Format=_SL110_&ID=AsinImage&MarketPlace=DE&ServiceVersion=20070822&WS=1&tag=webbigode-21" ></a><img src="http://ir-de.amazon-adsystem.com/e/ir?t=webbigode-21&l=as2&o=3&a=B004DI7A5S" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
`;
// 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