I am trying to replace the javascript code in html by javascript
So I am testing like this.
var test = new String("<script type=\"text/javascript\"> test </script>");
test.replace(/<script type=\"text\/javascript\">.+<\/script>/g,"");
//this doesn't match
console.log(test.toString());
test.replace doesn't match and console.log shows this.(nothing happens!)
<script type="text/javascript"> test </script>
Is there any mistake??
.replacereturns a new string. But the more important question is, why are doing this? What problem are you trying to solve here?new String()or.toString()there - every string in JS is an object of type string.new Stringis a terribly bad idea. Anyways, whitebear: why’re you trying to do this? It doesn’t seem like a good idea somehow.new Stringthought, because it makes things very confusing.