日期:2014-05-19  浏览次数:20901 次

关于正则表达式
求指教如何使用正则表达式从一段html文本中去除所有<embed></embed>标签、得到剩余的html。
如 <html>
<head>
<title>测试</title>
</head
<body>
     <p>fsgdfgvdsfgdfshgbdsfgsfdgfdgfd</p>
<div id="player404352-parent" style="text-align: center">&nbsp;</div>
注,因该医院楼顶建有停机坪、大厅内有价值&lt;a href=&quot;http://news.sina.com.cn/c/2012-11-<br />
<embed height="400" width="400" src="/DailyHG/userfiles/flash/efe50077-6767-4cde-a716-67d124e130e1.swf" type="application/x-shockwave-flash" play="true" loop="true" menu="true"></embed>
<br />
</body>
</html>

去除embed标签后、就是下面这样、

<html>
<head>
<title>测试</title>
</head
<body>
     <p>fsgdfgvdsfgdfshgbdsfgsfdgfdgfd</p>
<div id="player404352-parent" style="text-align: center">&nbsp;</div>
注,因该医院楼顶建有停机坪、大厅内有价值&lt;a href=&quot;http://news.sina.com.cn/c/2012-11-<br />
<br />
</body>
</html>

求指教如何写
------最佳解决方案--------------------

String content = "<html>\r\n"
+ "<head>\r\n"
+ "<title>测试</title>\r\n"
+ "</head>\r\n"
+ "<body>\r\n"
+ "<p>fsgdfgvdsfgdfshgbdsfgsfdgfdgfd</p>\r\n"
+ "<div id=\"player404352-parent\" style=\"text-align: center\">&nbsp;</div>\r\n"
+ "注,因该医院楼顶建有停机坪、大厅内有价值&lt;a href=&quot;http://news.sina.com.cn/c/2012-11-<br />\r\n"
+ "<embed height=\"400\" width=\"400\" src=\"/DailyHG/userfiles/flash/efe50077-6767-4cde-a716-67d124e130e1.swf\" type=\"application/x-shockwave-flash\" play=\"true\" loop=\"true\" menu=\"true\"></embed>\r\n"
+ " <br />\r\n" + "</body>\r\n" + "</html>\r\n";
System.out.println(content.replaceAll("<embed[^\n]*?></embed>", ""));

------其他解决方案--------------------
<embed[^\n]*?></embed>

------其他解决方案--------------------
如何从文本中取出来呢?怎么运用这段正则表达式呢?
------其他解决方案--------------------
引用:
<embed[^\n]*?></embed>
如何从文本中取出来呢?怎么运用这段正则表达式呢? 
------其他解决方案--------------------
个人认为:<embed[^>]+></embed>.*\r\n 要好些
------其他解决方案--------------------
:<embed[^>]+?></embed>.*\r\n
------其他解决方案--------------------
引用:
引用:<embed[^\n]*?></embed>如何从文本中取出来呢?怎么运用这段正则表达式呢?


c#是用Regex这个类操作的..Java不清楚了..查一查..
------其他解决方案--------------------
引用:
:<embed[^>]+?></embed>.*\r\n
可以了、谢谢、分不多、给你啦