I need to replace some words with a html link tag, but I ONLY want to do this when the word is NOT found inside an existing link element.
So I'd like to replace FOO in this markup:
<p>Once upon a FOO there was a BAR</p>
But I do NOT want to replace FOO in this markup:
<p>Once upon a <a href="coolsite.net">FOO</a> there was a BAR</p>
I don't really understand how to solve this. I'm guessing something to do with look aheads and look behinds, but I don't really know where to start.
It's ok to run it server side to avoid Safaris limited support for look ahead/behinds.