My experience with Regex is a little more than intro, so this is a challenge. Perhaps some math/physics/someone can figure it out...
We have to wrap certain words/phrases with a <span class="tooltip"></span>
so that a relevant tooltip is displayed for the contents of the span. The challenge comes in how to avoid not wrapping a word twice if it is part of another phrase that was already wrapped.
The example: "Use Twitter Analyzer for analytics".
Both Twitter and Twitter Analyzer have tooltips, but only the Twitter Analyzer needs to be wrapped in the above. This is achieved by ensuring we search for the longest phrases first.
How do you prevent (using only Regular Expressions) the shorter phrase of the two from being wrapped again if it is already wrapped in another span?
Furthermore, Twitter and Twitter Analytics are only two examples of an entire list, so it needs to be generic.
Any ideas?