I have a regular expression to escape all special characters in a search string. This works great, however I can't seem to get it to work with word boundaries. For example, with the haystack
add +
or
add (+)
and the needle
+
the regular expression /\+/gi
matches the "+". However the regular expression /\b\+/gi
doesn't. Any ideas on how to make this work?
Using
add (plus)
as the haystack and /\bplus/gi
as the regex, it matches fine. I just can't figure out why the escaped characters are having problems.