I tried to remove the external script tag from a string using a regular expression.
var data = "<p>Valid paragraph.</p><p>Another valid paragraph.</p><script>alert123</script><script type='text/javascript' src='123'>Dangerous scripting!!!</script><script type='text/javascript' src='123'/><p>Last final paragraph.</p>";
data.replace(/<script[^>]\(\src=\)*>(?:(?!<\/script>)[^])*<\/script>/g, "")
output should be
"<p>Valid paragraph.</p><p>Another valid paragraph.</p><script>alert123</script><p>Last final paragraph.</p>";
but it not validating. how to fix this issue?