RegEx - Remove HTML hyperlinks based on the link text

Posted by Rob on Stack Overflow See other posts from Stack Overflow or by Rob
Published on 2010-03-19T04:23:07Z Indexed on 2010/03/19 4:31 UTC
Read the original article Hit count: 280

Filed under:
|
|

Hi, I have some text that has HTML hyper-links in it. I want to remove the hyperlinks, but only specific ones.

e.g. I start with this:

This is text <a href="link/to/somewhere">Link to Remove</a> and more text with another link <a href="/link/to/somewhere/else">Keep this link</a>

I want to have:

This is text and more text with another link <a href="/link/to/somewhere/else">Keep this link</a> 

I have this RegEx expression,

<a\s[^>]*>.*?</a>

... but it matches ALL of the links.

What do I need to add to that expression to match only the links with the link-text 'Remove' (for example) in it?

thanks in advance.

© Stack Overflow or respective owner

Related posts about regex

Related posts about c#