I need regex with all english keyboard characters that works from all situations. Right now, I'm using this:
/^[a-zA-Z0-9!@#\$%\^\&*)\]\[(+=._-].*/
But the text like this don't work:
"I'm good!", told Billy!
How could I fix this?
preg_match("#^[a-z0-9\r\n\t " . preg_quote('`~!@#$%^&*()_+{}[]:";\'<>?,./'). "].*#i", $string, $matches)
如果您不需要TAB和ENTER键,则可以删除\\r\\n\\t
Space is missing.
The .*
at the end is not what you wanted.
Instead, end with *
to repeat the character set; then have a $
to 'anchor' the regexp at the end of the string.
/^[ -~]*$/
might work correctly -- it includes space and all visible characters. See an ascii chart to verify. Or you may need to add \\t
for tab and something for Return
.
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.