我正在尝试找到与正则表达式匹配的PHP正则表达式,例如带空格的“ Hello World”,还匹配不带空格的“ HelloWorld”。
You could use:
/^Hello ?World$/
Or you don't care the number of spaces:
/^Hello *World$/
Or it could also be blank chars like tab, then use \\s
instead a space.
Generally that would be:
/[a-zA-Z ]+/
If you want numbers, too:
/[a-zA-Z0-9 ]+/
You would need to set some sort of boundary. If the string just contains this, you can use start and end delimiters:
/^[a-zA-Z0-9 ]+$/
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.