I want to create RegEx in JavaScript that matches the word but is not part of it. I think something like \ bword \ b works well for this. My problem is that this word is not known in advance, so I would like to collect a regular expression using a variable containing a word that will match something line by line:
r = "\b(" + word + ")\b"; reg = new RegExp(r, "g"); lexicon.replace(reg, "<span>$1</span>"
which I noticed does not work. My idea is to replace certain words in the paragraph with a span tag. Can anybody help me?
PS: I am using jQuery.
javascript jquery regex
Andre Garzia
source share