Hi Guys, I am a Javascript Junkie and wishing to test around some codes.
new RegExp("user=" + un + "[\"'\\s>]", "i")
what will this actually mean?
It was from a site, and it actually works!
I especially don't get the [\"'\\s>] part.
Hi Guys, I am a Javascript Junkie and wishing to test around some codes.
new RegExp("user=" + un + "[\"'\\s>]", "i")
what will this actually mean?
It was from a site, and it actually works!
I especially don't get the [\"'\\s>] part.
[ and ] signify a character class. Basically, it will match one of any characters found within. The backslash \ escapes special characters. So you'll see that the first double-quote is escaped, showing we're looking for the " char within the value, and not merely using the " within our regular expression to wrap around a value. Then the single-quote ' is considered, followed by a backslash (literal - so it too must be escaped \\ looks for one backslash). It appears the original was indicating a space, which is \s. And then the greater-than symbol.
[\"'\s>] means any of the following characters: " ' space >
So, assuming un = "abc" your regex would match any of the following:
user=abc"
user=abc'
user=abc // There is a space after abc.
user=abc>
[\"'\\s>]
represents a char class containing 4 thing: a double quote, a single quote, a \s, and a >. It matches either one of these four once. The \s in turn could mean a single white space which could come from a space, tab, newline, carriage return.
The extra \ you see are for escaping.