去掉<script>标记
<script language="javascript">
function abc(){
alert('a');
}
</script>
<a href='bbbb'>abc</a>
<script language="javascript">
function abc()
{
document.write('<a href='a'>帮我去掉这段js</a>');
document.write('<a href=a[i]+c>')郁闷一天</a>;
}</script>
<a href="aaaa">agsdf</a>
最后结果就保留
<a href='bbbb'>abc</a>
<a href="aaaa">agsdf</a>
------解决方案--------------------public class Main {
public static void main(String[] args) {
StringBuffer sb=new StringBuffer();
sb.append("<script language= \"javascript \"> " +
"function abc(){ " +
"alert( 'a '); " +
"}" +
"</script> " +
"<a href= 'bbbb '> abc </a> " +
"<script language= \"javascript \"> " +
"function abc() " +
"{ " +
"document.write( ' <a href= 'a '> 帮我去掉这段js </a> '); " +
"document.write( ' <a href=a[i]+c> ')郁闷一天 </a> ; " +
"} </script> " +
"<a href= \"aaaa \"> agsdf </a> "
);
System.out.println(sb.toString());
String res = sb.toString().replaceAll("<script\\s.*?>.*?</script>","");
System.out.println(res);
}
}