JSLINT: bad descent
1 answer
You need to double the backslash.
The string constants in this expression (the expression whose value is passed to the RegExp constructor) are interpreted as such before the regular expression parser sees them. Backslashes are metacharacters in string constant syntax. That way, if you don't double them (that is, if you don't express them as slash parts in a string), the regex parser won't see them at all.
Thus, if "s" is "hello world", your code is equivalent to:
var r = /^s*hello worlds*$/i;
That is, a regular expression that matches zero or more instances of the letter "s", followed by a search string, followed by zero or more "s" characters at the end of the string.
+4
source to share