我正在寻找一个正则表达式模式来匹配在美国键盘上找到的所有字符。现在,我只匹配字母、数字和空格,所以看起来像
^[a-zA-Z0-9\\s]+$
但现在我需要它来匹配键盘上找到的任何字符。如果字符串也为空,我什至希望它匹配。
最佳答案
^[\x00-\x7F]*$
对于 0-n ASCII characters ^[\x20-\x7F]*$
会更准确,正如 Nick D. 所提到的在评论中:从 SPACE 到 DEL。详见 regular-expressions.info :
\xFF where FF are 2 hexadecimal digits
Matches the character with the specified ASCII/ANSI value, which depends on the code page used. Can be used in character classes
[\x20-\x7F]
是一个字符类,在这里指定了一个字符范围。
关于regex - 正则表达式匹配美国键盘上的所有字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1444666/