const regex = /https:\/\/tld\.example\.com(.*?)ref=testetghe/;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('https:\\\/\\\/tld\\.example\\.com(.*?)ref=testetghe', '')
const str = `icon-459822882 attributeIcon-1499443538" focusable="false" height="100%" role="img"
width="100%"><use xlink:href="#icon-clipboard"></use></svg><dl class="itemAttribute-1164924913"><dd
class="attributeValue-3783238563"><a class="attributeLink-387024144" rel=" noopener noreferrer"
href="https://tld.example.com/en/main?id=325235231763265&ref=testetghe"
title="Opens in a new window." target="_blank`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
if ((m = regex.exec(str)) !== null) {
// 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