I am trying to wrap some words with HTML tags, for that I am using regular expressions. I am almost there:
This is my regexp
/((apple|banana|cherry|orange)\b\s?)+/gi
and this is my replacement:
<em>$&</em>
which works perfectly for my example text:
Apple Banana apple cherry, Cherry orange and Oranges Apple, Banana
the result being:
<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 this but I would reaaaaaally like to have it perfect and not include the space after the final match.
i.e. my perfect result would be (see the tag shifted left after "Cherry orange"):
<em>Apple Banana apple cherry</em>, <em>Cherry orange</em> and Oranges <em>Apple</em>, <em>Banana</em>