How can I check the plus sign with regular expressions?

I am trying to check the plus sign with PHP and regular expressions.

Here is the code I got so far.

preg_replace('#[^-a-zA-Z0-9_&; ]#', '', $abcd)
+3
source share
2 answers

You may just need to avoid the "plus" sign with a backslash: \+.

+5
source

Add + to the list.

preg_replace('#[^-a-zA-Z0-9_&; +]#', '', $abcd)
0
source

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


All Articles