Can't escape the backslash with regex?

前端 未结 6 783
别那么骄傲
别那么骄傲 2020-11-22 09:04

I\'m using the following regex

^[a-zA-Z0-9\\\',!;\\?\\$\\^:\\\\\\/`\\|~&\\\" @#%\\*\\{}\\(\\)_\\+\\.\\s=-]{1,1000}$

I know it\'s ugly,

6条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 10:06

    The backslash \ is the escape character for regular expressions. Therefore a double backslash would indeed mean a single, literal backslash.

    \ (backslash) followed by any of [\^$.|?*+(){} escapes the special character to suppress its special meaning.

    ref : http://www.regular-expressions.info/reference.html

提交回复
热议问题