I have html code as a string variable
like a = “<span> Spain will win ……. </span>”
and I want to heightlight “spa” in the String.
I have to use RegExp, How should I write the pattern that it ignores the “spa” on span tag, but highlight in Spain.
Thanks
JavaScript doesn’t support lookbehind, so you’re a bit limited, but this should work:
Explanation:
\b: Assert that the match starts at a word boundary.Spa: MatchSpa.(?!...): Assert that it is impossible to match the following:n: Ann, followed by…[^>]*: zero or more non->characters, followed by…>: a>.