[英]regex with all keyboard characters
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.
请参阅ascii图表进行验证。 Or you may need to add
\\t
for tab and something for Return
. 或者,您可能需要为
\\t
tab添加\\t
并为Return
添加一些内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.