Uncaught SyntaxError : Unexpected token ;

前端 未结 2 508
隐瞒了意图╮
隐瞒了意图╮ 2021-01-24 17:09

I am getting Uncaught SyntaxError: Unexpected token ; at THE LINE NUMBER

    // HTML Helper
    var documentHtml = function(html){
            


        
2条回答
  •  悲哀的现实
    2021-01-24 17:49

    The problem is:

    //gi
    

    At the time of writing, SO's highlighting shows the problem with the original: the regex seems to be /.

    It should be:

    /<\/(html|head|body|title|meta|script)>/gi
    

    Since Javascript uses forward slashes to delimit regexes, you have to escape any forward slash inside it with a backslash.


    IMO, using forward slashes for regexes was the most unfortunate syntax decision of JavaScript:

    1. Parsing JavaScript is difficult because of / starting multiline comments, single line comments, division, and regexes. (Sublime, my editor choice, gets it wrong. Dreamweaver gets it wrong.)

    2. It makes regexes for URIs/URLs particularly ugly.

提交回复
热议问题