admin管理员组文章数量:1356945
Does anybody know why I get a Bad escapement
error on JSHint using the follow code?
var regexS = '[\?&]' + name + '=([^&#]*)';
Does anybody know why I get a Bad escapement
error on JSHint using the follow code?
var regexS = '[\?&]' + name + '=([^&#]*)';
Share
Improve this question
edited Aug 9, 2014 at 17:41
fernandopasik
10.5k7 gold badges51 silver badges56 bronze badges
asked Nov 1, 2012 at 0:25
user1790061user1790061
491 silver badge3 bronze badges
2 Answers
Reset to default 6Just 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 es after it. This is why \\ es out as a single slash (if you look at the source of this question you will find I needed to quadruple the \).
Other mon escape sequences are \n for newline and \t for tab.
本文标签: javascriptBad escapement JSHintStack Overflow
版权声明:本文标题:javascript - Bad escapement JSHint - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744058096a2583620.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论