This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
To begin, I'm not even sure regex is the best tool for this. I want to do a replace all match of all occurrences of a word, except when it occurs between < and >. I found out to use the /b for word boundry matches so it only replaces full word matches, but trying to find only those outside tags is difficult. I tried to implement some sort of lookahead and look behind scheme but it failed.
So if the string is "<Hello There World>Hello There World", and I want to replace "There" with "bob"; the final string would be "<Hello There World>Hello bob World"
To begin, I'm not even sure regex is the best tool for this.
It is probably not -- but it is doable. For one level tags -- no nesting, is should be straight forward. For two levels, it is still doable. For three or more levels, it gets even harder, and is probably not worth it.
I tried to implement some sort of lookahead and look behind scheme but it failed.
For one level, lookahead should work. Just search for the word, followed by a lookahead of anything but the close tag (zero or more), followed by (still part of lookahead) either the open tag, or end of input.