Preg_match alphanumeric -_ '"and space

Does anyone have a regex that allows alphanumeric and -_ ", 'as well as spaces?

+5
source share
2 answers

Try the following:

/^[A-Za-z0-9-_",'\s]+$/
+3
source

I read quite a lot about the \ s flag in regex, I see that it rang out like candies in all the stacks, but it would seem that the \ s flag matches all metacharacters and also skips line breaks.

This will ignore the filtered user input for all types of characters that you do not want to use in your software, website or database.

\s , , , lol...

: /[^\p{Xan}]++$/D

  • \p{Xan} , , , .

  • ++ ,

  • $/D regex ,

\ s flag:

: http://php.net/manual/en/reference.pcre.pattern.modifiers.php

s (PCRE_DOTALL)      , , . . Perl/s. , [^ a], , .

:

: http://en.wikipedia.org/wiki/Metacharacter

- , ( ) , .

11 , \, :

[, \, ^, $, ., |, ?, *, +, ( ). [1]

, . 1 + 1 = 2, 1 + 1 = 2. .

0

All Articles