Regular Expression Boundaries and Special Characters

I have a regex to avoid all special characters in the search bar. This works great, however I cannot get it to work with layers. For example, with haystack

add +

or

add (+)

and needle

+

regular expression /\+/gimatches "+". However, the regular expression /\b\+/gidoes not have. Any ideas on how to make this work?

Using

add (plus)

like a haystack and /\bplus/gias a regular expression, it corresponds to a fine. I just can't understand why runaway characters have problems.

+3
source share
3 answers

\b : , , . , , . ( " " - , .) :

add +

... , a , d, . \b (/\b\+/) +, , .

+5

- ; , , , . . , , , .

+1

:

/\b\s?+/gi

Edit:

, . + :

/\b[^+]*+/gi
0

Source: https://habr.com/ru/post/1754503/


All Articles