我正在使用事物url正则表达式验证,并且也已将eslint集成到项目中。
let url = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/
但是当我编译我的代码时出现错误
4:49 error Unnecessary escape character: \` no-useless-escape
4:62 error Unnecessary escape character: \. no-useless-escape
4:75 error Unnecessary escape character: \$ no-useless-escape
4:79 error Unnecessary escape character: \( no-useless-escape
4:81 error Unnecessary escape character: \) no-useless-escape
4:83 error Unnecessary escape character: \* no-useless-escape
4:85 error Unnecessary escape character: \+ no-useless-escape
答案 0 :(得分:6)
快速浏览一下,我可以看到您正在转义正则表达式字符类中的字符,而这些字符可能不需要转义。因此,请尝试删除这些no-useless-escape
:
let url = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!$&'()*+,;=.]+$/