I have some links like this:
<a href="http://illegallink.com"><img src="something.jpg" /><a href="http://legallink.com">legal</a></a>
I want to remove all links that does not have "legallink.com" in it. But still keep the content. So the above input would output:
<img src="something.jpg" /><a href="http://legallink.com">legal</a>
It should work recursively through the links.
I found this regex that removes all links: /<\\/?a(\\s+.*?>|>)/
, but I want it to keep links where href is legallink.com.
Can this be done with regex? Or should I use a DOM parser?