I need a regex (for use开发者_如何学Go with PHP) that will do this:
- replace a given word with another - do NOT replace this word, when it is within a href-attrib of an a-tag of HTMLexample:
searchword is "foobar", replace will be "someother" sentence1: "this is a foobar task" sentence2: "this is a <a href="/foobar.php">foobar</a>"will be:
1 -> "this is a someother task" 2 -> "this is a <a href="/foobar.php">someother</a>"note that the href foobar is still there!
You may try this one:
[^href=".*/]foobar
Altough, you will have to take care about the first sign just before the foobar, which will also be replaced, i.e., >foobar -> someother. So, try some backreference, or combine it with some other regexp.
For the future, make sure that you specify the question exactly, and write what you have tried so far. Just like Bobby mentioned in his comment.
精彩评论