i create this form for strip <script></script> tags but this form not working
i create this form for strip <script></script>
tags but this form not working please any one modify this form to start working
<html>
<head>
<script language='javascript'>
function alfa(s) {
return s.replace(/<script>[^<\/script>]*<\/script>/g, "");
}
</script>
</head>开发者_如何学编程;
<body>
<form>
<textarea name="txt" style="width: 300px; height: 150px"></textarea><br />
<input type="button" value="Remove script tags" onClick="txt.value=alfa (txt.value)">
</form>
</body>
</html>
return s.replace(/<script>[\s\S]*?<\/script>/g, "");
[\s\S]
means "any character" (dot in Javascript doesn't match \n), the question mark makes the * "lazy". Use [^ ]
only for negation of single character.
[^<\/script>]
means "any character except <, /, s, c, r, i, p, t or >".
Try this one
s.replace(/<script[ >][\s\S]*?<\/script>/g, "");
Your starting tag is not neccesarily <script>
. The tag name can befollowed by a space and additional attributes.
Also you use the []
character class the wrong way.
精彩评论