Enable whitespace in php regular expresssion
I want to have A-Z, 0-9 and whitespace ignored in regular expression, currently I have this, it works but whitespaces are ignored开发者_StackOverflow too but I need them.
preg_match_all("/[^\w]/",$string,$matches);
\s
represents whitespace characters. So if you want to match every character except word characters (\w
) or whitespace characters (\s
), try this:
preg_match_all("/[^\w\s]/",$string,$matches);
精彩评论