JSLint 报告以下行的不安全“^”。这是为什么?还是只要我想否定一个字符类,它就会提示?
// remove all non alphanumeric, comma and dash characters
"!$7s-gd,&j5d-a#".replace(/[^\w,\-]/g, '');
最佳答案
只有在底部选择了选项时才会执行此操作:
Disallow insecure . and [^...] in /RegExp/
来自 the docs :
true if . and [^...] should not be allowed in RegExp literals. These forms should not be used when validating in secure applications.
所以回答你的问题,如果你用 ^
开始一个正则表达式并且它被选中,是的,它每次都会抛出错误。问题在于 unicode 字符,您几乎允许其中的任何内容,并且可能存在安全问题或验证绕过问题。而不是禁止某些东西(可以绕过),只允许哪些字符是有效的。
关于javascript - 正则表达式中的 JSLint "insecure ^",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15937618/