java清除html标签
2013-10-30 21:41
417 查看
java清除html标签
import java.util.regex.Matcher;import java.util.regex.Pattern;
public class HTMLSpirit{
public static String delHTMLTag(String htmlStr){
String regEx_script="<script[^>]*?>[\\s\\S]*?<\\/script>"; //定义script的正则表达式
String regEx_style="<style[^>]*?>[\\s\\S]*?<\\/style>"; //定义style的正则表达式
String regEx_html="<[^>]+>"; //定义HTML标签的正则表达式
Pattern p_script=Pattern.compile(regEx_script,Pattern.CASE_INSENSITIVE);
Matcher m_script=p_script.matcher(htmlStr);
htmlStr=m_script.replaceAll(""); //过滤script标签
Pattern p_style=Pattern.compile(regEx_style,Pattern.CASE_INSENSITIVE);
Matcher m_style=p_style.matcher(htmlStr);
htmlStr=m_style.replaceAll(""); //过滤style标签
Pattern p_html=Pattern.compile(regEx_html,Pattern.CASE_INSENSITIVE);
Matcher m_html=p_html.matcher(htmlStr);
htmlStr=m_html.replaceAll(""); //过滤html标签
return htmlStr.trim(); //返回文本字符串
}
}
相关文章推荐
- java清除字符串中的html标签
- Java 语言实现清除带 html 标签的内容
- JAVA 清除 html标签
- java清除html标签
- Java清除HTML标签
- Java 语言实现清除带 html 标签的内容方法
- Java清除HTML标签
- Java清除HTML标签
- java 清除 HTML标签格式、CSS 样式
- JAVA:清除HTML标签
- java清除html标签
- Java中替换HTML标签的方法代码
- Java过滤任意(script,html,style)标签符,返回纯文本--封装类
- java清除html转义字符
- java获取html文档中的所有img标签
- 如何在java注解中加入原生html标签内容
- 如何使用java的正则表达式提取html标签?
- java正则表达式去掉html标签
- java 去掉html标签 使用正则表达式删除HTML标签。
- java把html标签字符转普通字符(反转换成html标签)