正则表达式匹配美国键盘上的所有字符 [英] Regular expression to match all characters on a U.S. keyboard
问题描述
我正在寻找一种正则表达式模式来匹配在美国键盘上找到的所有字符.现在,我只匹配字母、数字和空格,所以它看起来像
I'm looking for a regex pattern to match all characters that are found on a U.S. keyboard. right now, I match only on letters and numbers and white space, so it looks like
^[a-zA-Z0-9\\s]+$
但现在我需要它来匹配键盘上的任何字符.如果字符串为空,我什至希望它也匹配.
But now I need it to match on any character found on a keyboard. I even want it to match if the string is empty as well.
推荐答案
^[\x00-\x7F]*$
对于 0-n ASCII 字符
^[\x20-\x7F]*$
会更准确,正如 Nick D. 在评论中提到的:来自 SPACE 到 DEL.
would be more accurate, as mentioned by Nick D. in the comment: from SPACE to DEL.
\xFF 其中 FF 是 2 个十六进制数字
\xFF where FF are 2 hexadecimal digits
将字符与指定的 ASCII/ANSI 值匹配,这取决于所使用的代码页.可用于字符类
Matches the character with the specified ASCII/ANSI value, which depends on the code page used. Can be used in character classes
[\x20-\x7F]
是一个字符类,在这里指定了一个字符范围.
[\x20-\x7F]
is a character class specifying here a range of characters.
这篇关于正则表达式匹配美国键盘上的所有字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!