0

i want to regex to remove any-link that start with example.com but i want to keep the text :

<a rel="nofollow" target="_blank" href="http://example.com/somepage/">some text</a>

I have tried a lot of regex with yahoo pipes and didn't work please help me guys.

2 Answers2

0

try this regex:

<a\s.+?example[.]com.+?>([^<]+)</a>

explain:

+? Matches the previous element one or more times, but as few times as possible.

[^character_group] Negation: Matches any single character that is not in character_group

Ria
  • 10,237
  • 3
  • 33
  • 60
  • workd but the text has been deleted i want to keep the text but temove the link – user3526447 Apr 12 '14 at 11:47
  • The text is in [capture group](http://stackoverflow.com/q/21880127) 1. Nothing else is captured. Use [`$1` or `\1`](http://stackoverflow.com/q/21880127) to get it. For more information, see the section on "Groups" in the [Stack Overflow Regular Expressions FAQ](http://stackoverflow.com/a/22944075/2736496). – aliteralmind Apr 12 '14 at 11:53
0

user3526447, depending on context there may be a problem with the expression in the first answer, because from the initial "a" tag, the .+ will potentially run over multiple urls until it hits "example". This may not be a problem in the context you are using, if you are only working on single urls.

Instead, replace

(<a[^>]*?)example\.com

with $1 or \1

zx81
  • 41,100
  • 9
  • 89
  • 105