Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
用多种语言进行了尝试,结果相同。
JavaScript 示例:
/[A-z]/.test("_"); // => true /[A-z]/.test("0"); // => false /[A-z]/.test("-"); // => false /[A-z]/.test("A"); // => true
为什么第一个案件没有返回false?
false
字符范围不是那么智能。它们基于 ascii 代码。查看Ascii 表。A-Z大小写范围之间存在特殊字符a-z,即:
A-Z
a-z
[ \ ] ^ _ `
所以,而不是A-z应该是A-Za-z.
A-z
A-Za-z