const regex = /(\bhref="(.*?)\b")(?!.*\1)?/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(\\bhref="(.*?)\\b")(?!.*\\1)?', 'g')
const str = ` <div>
<a href="showthread.php?t=5239160" id="thread_title_5239160">программа для точного определения местоположения любого гаджета</a>
<span class="smallfont" style="white-space:nowrap">(<img class="inlineimg" src="https://static.kharkovforum.com/images/misc/multipage.gif" alt="перейти на страницу" border="0" /> <a href="showthread.php?t=5239160">1</a> <a href="showthread.php?t=5239160&page=2">2</a>)</span>
</div>
<div class="smallfont">
<span style="cursor:pointer" onclick="window.open('member.php?u=502041', '_self')">I-am</span>
</div>
`;
// 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