Android Html 过滤标签
来源:互联网 发布:php对小数的处理 编辑:程序博客网 时间:2024/05/18 00:27
String content="<div class=\\\"para\\\" label-module=\\\"para\\\" style=\\\"word-wrap: break-word; margin-bottom: 5px; zoom: 1;\\\">巴斯大学(University of Bath)<span style=\\\"position: relative; vertical-align: baseline; top: -0.5em; margin-left: 2px; cursor: default; padding-right: 2px; padding-left: 2px;\\\">[1]</span><a class=\\\"sup-anchor\\\" name=\\\"ref_[1]_16367\\\" style=\\\"position: relative; top: -50px;\\\"> </a> 是一所以科研为向导的英国顶尖名校,科研实力被评定为世界领先<span style=\\\"position: relative; vertical-align: baseline; top: -0.5em; margin-left: 2px; cursor: default; padding-right: 2px; padding-left: 2px;\\\">[2]</span><a class=\\\"sup-anchor\\\" name=\\\"ref_[2]_16367\\\" style=\\\"position: relative; top: -50px;\\\"> </a> 。</div><div class=\\\"para\\\" label-module=\\\"para\\\" style=\\\"word-wrap: break-word; margin-bottom: 5px; zoom: 1;\\\">巴斯大学是全英前10的著名学府,历年最高排名全英第4(分别于2003年和2015年)<span style=\\\"position: relative; vertical-align: baseline; top: -0.5em; margin-left: 2px; cursor: default; padding-right: 2px; padding-left: 2px;\\\">[3]</span><a class=\\\"sup-anchor\\\" name=\\\"ref_[3]_16367\\\" style=\\\"position: relative; top: -50px;\\\"> </a> 。成立于1966年,现任校监为女王<a target=\\\"_blank\\\" href=\\\"http://baike.baidu.com/view/47650.htm\\\">伊丽莎白二世</a>的三子 - <a target=\\\"_blank\\\" href=\\\"http://baike.baidu.com/subview/3035700/11062139.htm\\\" data-lemmaid=\\\"8488157\\\">爱德华王子</a>, 威塞克斯伯爵<span style=\\\"position: relative; vertical-align: baseline; top: -0.5em; margin-left: 2px; cursor: default; padding-right: 2px; padding-left: 2px;\\\">[4]</span><a class=\\\"sup-anchor\\\" name=\\\"ref_[4]_16367\\\" style=\\\"position: relative; top: -50px;\\\"> </a> 。</div><div class=\\\"para\\\" label-module=\\\"para\\\" style=\\\"word-wrap: break-word; margin-bottom: 5px; zoom: 1;\\\"><img src=\\\"http://g5bk.com:8080/MojieProject/file/smallContentFile/418ef337-8b48-4a2d-bf59-91f0a33259c3_47802525_5(1).jpg\\\" w=\\\"2599\\\" h=\\\"1640\\\" style=\\\"width: 778px;\\\"/><br></div><div class=\\\"para\\\" label-module=\\\"para\\\" style=\\\"word-wrap: break-word; margin-bottom: 5px; zoom: 1;\\\">大学位于<a target=\\\"_blank\\\" href=\\\"http://baike.baidu.com/view/58688.htm\\\">英格兰</a>南部的世界遗产城市-<a target=\\\"_blank\\\" href=\\\"http://baike.baidu.com/subview/89823/12443073.htm\\\" data-lemmaid=\\\"1620585\\\">巴斯</a>。根据英国各媒体近十年公布的英国大学排行榜,巴斯大学被稳固的确立为<span style=\\\"position: relative; vertical-align: baseline; top: -0.5em; margin-left: 2px; cursor: default; padding-right: 2px; padding-left: 2px;\\\">[3]</span><a class=\\\"sup-anchor\\\" name=\\\"ref_[3]_16367\\\" style=\\\"position: relative; top: -50px;\\\"> </a> 英国排行前十的大学。</div><div class=\\\"para\\\" label-module=\\\"para\\\" style=\\\"word-wrap: break-word; margin-bottom: 5px; zoom: 1;\\\"><a target=\\\"_blank\\\" href=\\\"http://baike.baidu.com/view/2416950.htm\\\">巴斯大学管理学院</a>被公认为英国最好的商学院之一, 在业界有极高的声誉,每年有大量本科毕业生进入伦敦顶级投行工作,在2016年完全大学指南排名中位居第1位。</div><div class=\\\"para\\\" label-module=\\\"para\\\" style=\\\"word-wrap: break-word; margin-bottom: 5px; zoom: 1;\\\"><img src=\\\"http://g5bk.com:8080/MojieProject/file/smallContentFile/418ef337-8b48-4a2d-bf59-91f0a33259c3_slide1-large(1).jpg\\\" w=\\\"640\\\" h=\\\"480\\\" style=\\\"width: 640px;\\\"/><br></div><div class=\\\"para\\\" label-module=\\\"para\\\" style=\\\"word-wrap: break-word; margin-bottom: 5px; zoom: 1;\\\">巴斯大学在2015完全大学指南英国大学排名上��居第8位<span style=\\\"position: relat\n";
/**
* 定义script的正则表达式
*/
private static final String REGEX_SCRIPT = "<script[^>]*?>[\\s\\S]*?<\\/script>";
/**
* 定义style的正则表达式
*/
private static final String REGEX_STYLE = "<style[^>]*?>[\\s\\S]*?<\\/style>";
/**
* 定义HTML标签的正则表达式
*/
private static final String REGEX_HTML = "<[^>]+>";
/**
* 定义空格回车换行符
*/
private static final String REGEX_SPACE = "\\s*|\t|\r|\n";
public static String delHTMLTag(String htmlStr) {
// 过滤script标签
Pattern p_script = Pattern.compile(REGEX_SCRIPT, Pattern.CASE_INSENSITIVE);
Matcher m_script = p_script.matcher(htmlStr);
htmlStr = m_script.replaceAll("");
// 过滤style标签
Pattern p_style = Pattern.compile(REGEX_STYLE, Pattern.CASE_INSENSITIVE);
Matcher m_style = p_style.matcher(htmlStr);
htmlStr = m_style.replaceAll("");
// 过滤html标签
Pattern p_html = Pattern.compile(REGEX_HTML, Pattern.CASE_INSENSITIVE);
Matcher m_html = p_html.matcher(htmlStr);
htmlStr = m_html.replaceAll("");
// 过滤空格回车标签
Pattern p_space = Pattern.compile(REGEX_SPACE, Pattern.CASE_INSENSITIVE);
Matcher m_space = p_space.matcher(htmlStr);
htmlStr = m_space.replaceAll("");
Pattern a_space = Pattern.compile(" ", Pattern.CASE_INSENSITIVE);
Matcher b_space = a_space.matcher(htmlStr);
htmlStr = b_space.replaceAll("");
return htmlStr.trim(); // 返回文本字符串
}
- Android 过滤 html标签
- Android Html 过滤标签
- 关于Android中如何过滤HTML标签
- ASP 过滤 HTML 标签
- .net 过滤html标签
- html标签过滤
- 过滤 HTML 标签例子
- php 过滤 html标签
- 过滤html标签
- 过滤HTML标签
- HTML标签过滤方案
- 过滤 html标签
- Java过滤HTML标签
- 过滤html标签
- js过滤HTML标签
- Java过滤html标签
- JAVA过滤html标签
- java 过滤html标签
- 关于PHP正则匹配问题...求教!
- UVa1585
- Sublime Text注册码
- Android 获取视频缩略图的 与播放视频的冲突
- 【求助】AsyncHttpResponseHandler无法覆盖抽象方法onFailture
- Android Html 过滤标签
- java设计模式大话之单例模式
- android 使用xutils3 https详解
- 经济动向g
- 对jsp:useBean 中id属性值,使用${ } 为什么只输出{ }
- CSS两端对齐
- Android读取Word文档
- iOS应用开发入门(3)——点击button控制textview
- eglSwapBuffers接口实现说明