admin管理员组

文章数量:1344973

I am using thing url regex validation and also have eslint integrated in project.

let url = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/

But when I pile my code getting below errors

  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

I am using thing url regex validation and also have eslint integrated in project.

let url = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/

But when I pile my code getting below errors

  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
Share Improve this question asked Mar 29, 2019 at 5:09 ProferProfer 64310 gold badges47 silver badges97 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 8

Well from a quick glance I can see that you are escaping characters inside your regex character classes which probably don't need to be escaped. So, try removing those no-useless-escapes:

let url = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!$&'()*+,;=.]+$/

本文标签: javascriptUnnecessary escape characternouselessescapeStack Overflow