Does javascript have literal strings?

后端 未结 6 1947
醉酒成梦
醉酒成梦 2020-12-05 12:48

In c# and ruby and many other languages you can denote a string as to not need escaping.
in c# its like this



        
6条回答
  •  萌比男神i
    2020-12-05 13:22

    I know it is six years late now, but I've got one solution to this ;)

    function literalString(regex) {
        return ('' + regex).slice(1, -1);
    };
    
    O.innerHTML = literalString(/\whatever\this\is/);

    You basically convert a regex to string and removes the first and last characters.

提交回复
热议问题