关于用正则替换一段html里面的数据
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<style>
br {display:inline; line-height:1px;}
</style>
<script src="http://libs.baidu.com/jquery/1.7.2/jquery.min.js"></script>
<script language=javascript>
$(document).ready(function(){
$("#sss").click(function(){
var start = $("body").html();
var start = start.replace("<script.*?<\/script>\s<(?!br\/)[^>]+>","<\/script>");
alert(start);
});
});
</script>
<body>
<div id="sss">清除BR标签</div>
123123123123<br />
123123123123<br />
123123123123<br />
123123123123<br />
123123123123<br />
123123123123<br />
123123123123<br />
123123123123<br />123123123123<br />
123123123123<br />
123123123123<br />123123123123<br />
123123123123<br /><script>parent.del('游客xxxxxx');</script>
<br />
123123123123<br />
123123123123<br />
</body>
</html>
<script.*?<\/script>\s<(?!br\/)[^>]+> 这个能匹配出来,但是好像替换不了,不知道哪里写错了。求帮助
这里写错了,应该是要这么替换,但成功不了 var start = start.replace("<\/script>\s<(?!br\/)[^>]+>","<\/script>"); 展开
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<style>
br {display:inline; line-height:1px;}
</style>
<script src="http://libs.baidu.com/jquery/1.7.2/jquery.min.js"></script>
<script language=javascript>
$(document).ready(function(){
$("#sss").click(function(){
var start = $("body").html();
var start = start.replace("<script.*?<\/script>\s<(?!br\/)[^>]+>","<\/script>");
alert(start);
});
});
</script>
<body>
<div id="sss">清除BR标签</div>
123123123123<br />
123123123123<br />
123123123123<br />
123123123123<br />
123123123123<br />
123123123123<br />
123123123123<br />
123123123123<br />123123123123<br />
123123123123<br />
123123123123<br />123123123123<br />
123123123123<br /><script>parent.del('游客xxxxxx');</script>
<br />
123123123123<br />
123123123123<br />
</body>
</html>
<script.*?<\/script>\s<(?!br\/)[^>]+> 这个能匹配出来,但是好像替换不了,不知道哪里写错了。求帮助
这里写错了,应该是要这么替换,但成功不了 var start = start.replace("<\/script>\s<(?!br\/)[^>]+>","<\/script>"); 展开
展开全部
start.replace("<script.*?<\/script>\s<(?!br\/)[^>]+>","<\/script>");
换成
start.replace(/<\/script>\s*<br\s*\/[^>]*>/igm,"</script>");
追问
"" 这里通过不了,页面都加载不正常
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询