Expression of expressions using word boundary to match alphanumeric and non-alphanumeric characters in javascript

Hi

I am trying to highlight a number of keywords using javascript and a regular expression, I ran into one problem, my keyword may contain literals and special characters, like in @text #number, etc. I use the word boundary to match and replace the whole word and not a partial word (contained in another word).

var pattern = new regular expression ('\ b' (+ keyword + ') \ b', gi); here this expression matches all keywords and selects them, however, if there weren’t any keyword selected, for example, β€œnumber:”,

I know that \ bword \ b matches the word boundary, and special characters are not alphanumeric characters, so they do not match the expression above.

Can you tell me which regular expression I can use to accomplish the above.

thanks,

Bhupen

0
source share

All Articles