I have a big html string, something like
<p>content</p>
<img src="example.jpg"/>
<p>another paragraph</p>
<a href="https://example.com/about-me.html?q=23424">about</a>
<a href="https://example.com/blog-link-1.html?q=123>blog</a>
and what I have to do is to clean the links but return the entire html string. I can use regex to do the cleaning for the link (remove after ?q=123),
const str = `<p>content</p>
<p>another paragraph</p>
<a href="https://example.com/about-me.html?q=23424">about me</a>
<br />
<a href="https://example.com/blog-link-1.html?q=123">blog</a>`
const result = str.replace(/https.*.html/g ,function(a) {
return a //what to do here?
})
console.log(result)
$('#content').html(result)
but I failed to replace the cleaned links back into the document string.