且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

有没有办法让JSLint对此正则表达式感到满意?

更新时间:2022-12-15 13:21:15

那是字符类;您不需要分隔符(例如:逗号).您可以通过将插入号(^)和破折号(-)放在重要位置来清理正则表达式,从而不必逃脱它们.

That's a character class; you don't need a separator (eg: the commas). You can clean up the regex by placing the caret (^) and the dash (-) in strategic positions so they don't need to be escaped.

/[!@#$%^&*?_~()-]/

应该工作.您还可以使用非文字字符类:

Should work. You can also use the non-word character class:

/\W/

任何不是字母(a-zA-Z),数字(0-9)或下划线(_)的匹配.

That matches anything that's not a letter (a-zA-Z), number (0-9) or underscore (_).