Does anybody know why I get a Bad escapement
error on JSHint using the follow code?
var regexS = '[\?&]' + name + '=([^&#]*)';
Just double escape the \
var regexS = '[\\?&]' + name + '=([^&#]*)';
Even though I'm guessing you'll be using this string for a Regex
object, characters in a string must be escaped correctly. By default, a \
attempts to escape the next character. If you add an extra one to be like \\
, it escapes the original \
and evaluates to a single \
in the final string.
\? isn't a valid escape character. Try replacing it with \\.
So it looks like:
var regexS = '[\\?&]' + name + '=([^&#]*)';
Keep in mind that "\" escapes the character that comes after it. This is why \\ comes out as a single slash (if you look at the source of this question you will find I needed to quadruple the \).
Other common escape sequences are \n for newline and \t for tab.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With