I am trying to wrap a few words with HTML tags because I use regular expressions. I'm almost there:
This is my regex
/((apple|banana|cherry|orange)\b\s?)+/gi
and this is my replacement:
<em>$&</em>
which works fine for my sample text:
Apple Banana apple cherry, Cherry orange and Oranges Apple, Banana
result:
<em>Apple Banana apple cherry</em>, <em>Cherry orange </em>and Oranges <em>Apple</em>, <em>Banana</em>
I could be pragmatic and live with it, but I would like it to be perfect and not include space after the final match.
i.e. my ideal result would be (see tag shifted to the left after "Cherry Orange"):
<em>Apple Banana apple cherry</em>, <em>Cherry orange</em> and Oranges <em>Apple</em>, <em>Banana</em>
javascript regex replace
Chris
source share