I am new to php regex. I am trying to match any number of words. For eg: A 'person name' can have any number of words, how can I do this?
I tried using \\w+\\
, but its matching only 1 word.
You can use the following for matching any number of words separated by whitespace:
[\w\s]+
See DEMO
PHP:
preg_match('~^[\w\s]+$~', $str);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.