Bad descent JSHint

Does anyone know why I am getting a Bad escapement error in JSHint using the following code?

 var regexS = '[\?&]' + name + '=([^&#]*)'; 
+4
source share
2 answers

Just double exit \

 var regexS = '[\\?&]' + name + '=([^&#]*)'; 

Although I assume that you will use this string for a Regex object, the characters in the string should be escaped correctly. By default, a \ tries to escape the next character. If you add an extra to look like \\ , it eludes the original \ and evaluates only one \ in the last line.

+6
source

\? not a valid evacuation symbol. Try replacing it with \\.

It looks like this:

 var regexS = '[\\?&]' + name + '=([^&#]*)'; 

Keep in mind that the "\" escapes the character that appears after it. That's why \\ comes out as a single slash (if you look at the source of this question, you will find that I needed to quadruple the number \).

Other common escape sequences are: \ n for newlines and \ t for tabs.

+4
source

Source: https://habr.com/ru/post/1443344/


All Articles