I have tryed to remove spcific links from html string by using reqular expressions.
I have a html string like this:
<a href="http://linkA.com/fdfdfdf">use this</a> to make this <a href="http://linkB.com/fdsfds">happen</a>
At the end I want it to look like this:
<a href="http://linkA.com/fdfdfdf">use this</a> to make this happen
I have tryed many patterns. At first I removed all href by this:
</?a(|\s+[^>]+)>
Then I have tryed many regexes:
<a\s+(?:[^>]*?\s+)?href="linkB.com([^"]*)
/<a[^>]*href="http\:\/\/linkB.com([^"]*)"[^>]*>.*<\/a>/
<a href="[^"]*?linkB*?">.*?</a>
<a\s.*?href=["']([^"']*?linkB[^"']*?)[^>]*>.*?<\/a>
(?=.*href=\"([^\"]*linkB[^"]*)")<a [^>]+>
<a[^>]*puustelli[^>]*>[^<]*<\/a>
None of them is doing exactly the thing I need to do. Magic needs to happen by finding only domain part of url. I want all links that are pointing to linkB disappear, but leave the anchor text on place.