const regex = /href="(\w[^"]+\/pdf4v\/\w[^"]+)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('href="(\\w[^"]+\\\/pdf4v\\\/\\w[^"]+)', 'gm')
const str = `<ul>
<li><a href="#" id="fav" onclick="return favoritesadd(8094,'fav.png','removefav.png');"><img id="fav8094" src="fav.png" alt="" border="0" /> <span id="fav8094">ADD TO WISHLIST</span></a></li>
<li class="sixcol right"><a href="https://documents.domain.com/content/updates/year18/jv/folder01/pdf/pdf8094.zip?exp=1567791065&hsh=5a49e7d4828603beddbfb058a1535f5e&dl=att&filename=pdf-00008094-16.pdf" class="tcenter"><img src="pdf.png" class="icon" align="left" />16<br /><span class="small">download pdf</span></a></li>
<li class="sixcol"><a href="https://documents.domain.com/content/updates/year18/jv/folder01/pdf4v/pdf4v8094.zip?exp=1567791065&hsh=246a7702296f7db363ecaa1746a8815a&dl=att&filename=pdf-00008094-40.pdf" class="tcenter"><img src="pdf.png" class="icon" align="left" />40<br /><span class="small">download pdf</span></a></li>
<div class="clear"></div>
<li><a href="/details.php?id=8094&num=1&ss=1" onclick="\$.open();return false;"><img src="/images/details.png" class="center" />Details</a></li>
</ul>`;
// 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