javascript - Why do regex constructors need to be double escaped? -
in regex below, \s denotes space character. imagine regex parser, going through string , sees \ , knows next character special.
but not case double escapes required.
why this?
var res = new regexp('(\\s|^)' + foo).test(moo); is there concrete example of how single escape mis-interpreted else?
you constructing regular expression passing string regexp constructor.
you need escape \ string literal can express data before transform regular expression.
Comments
Post a Comment