java代码用正则表达式去除html标签
来源:互联网 发布:中老年女雪地靴淘宝 编辑:程序博客网 时间:2024/06/14 22:31
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(); //返回文本字符串
}
}
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标签
- 正则表达式去除html标签
- 正则表达式去除html标签
- 利用正则表达式实现去除所有HTML标签代码
- java用正则去除html标签
- java用正则去除html标签
- java用正则去除html标签
- java使用正则表达式去除字符串的html标签
- java/android 正则表达式去除所有HTML标签
- JAVA正则表达式去除标签
- 利用正则表达式去除HTML标签
- 正则表达式,去除所有HTML标签
- 正则表达式,去除所有HTML标签
- python正则表达式去除html标签
- C# 正则表达式,去除所有HTML标签
- C++中delete和delete[]的区别
- JAVA字符截断保留尾部
- jquery中的trigger和triggerHandler区别
- 关于委托泛型的回调测试
- Android C2DM----客户端
- java代码用正则表达式去除html标签
- HUNNU11354:Is the Name of This Problem
- Linux下的多线程编程
- 电子支付概述(1)
- BUG:给Nexus7编译Android4.2的时候出现 fatal error: map: No such file or directory
- Android C2DM学习——服务器端代码开发 .
- 如何理解Spring的核心思想IOC【Spring是后宫,javabean是美女】
- iOS程序发布测试1-准备
- oralce截取中文字符去掉特殊字符