I'm trying to replace all instances of a word, say "foo" between some HTML tags.
<span id=foo> blah blah foo blah foo blah </span>
I want to replace all instances of foo that are not in the tag with bar, so the end result is:
<span id=foo> blah blah bar blah bar blah </span>
Notice that "foo" in the span tag has not been replaced.
I can manage to get the first (or last) occurance of "foo" replaced with my regular expression, but not multiple instances. Is this a situation where I should give up and not attempt to parse this with a regular expression?
Here is the regular expression that sort of works:
RegExp('(>[\\w\\s]*)\\bfoo\\b([\\w\\s]*<)',"ig"
or without javascript syntax:
s/>([\w\s]*)\bfoo\b([\w\s]*<)/
this syntax allows me to match (or should) match things like
[foo] but not bar-foo or barfoobar... any occurance of foo that will be replaced needs to stand on it's own, it can not be contained in another word.
As a note, the "blah blah" is of varying length, and can be many different words, no words, or any combination of these.
Thanks for any suggestions.