console.log(/^[0-9a-zA-Z]+[~!@#$%^&*_+-=]+$/.test("123456"));
false
,因为该字符串不以~!@#$%^&*_+-=
字符结尾,但在运行时它返回了true
。为什么会返回true
?console.log(/^[0-9a-zA-Z]+[~!@#$%^&*_+-=]+$/.test("123456"));
false
,因为该字符串不以~!@#$%^&*_+-=
字符结尾,但在运行时它返回了true
。为什么会返回true
?a-b
基于字符 a
、b
的“字符值”。http://www.ecma-international.org/ecma-262/8.0/index.html#sec-ecmascript-language-types-string-type 表明字符串基本上使用 UCS-2,即范围在 0 到 127 的字符值与 ASCII 匹配(0 到 255 匹配 ISO 8859-1(Latin-1))。 - melpomene
!@#$%^&*_+-=]+$/”匹配?它没有一个或多个字符在[!@#$%^&* _ + - =]中。 - iinux