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

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -