转自:http://lbs.iteye.com/blog/208056
public static String Html2Text(String inputString) {
String htmlStr = inputString; //含html标签的字符串
String textStr ="";
java.util.regex.Pattern p_script;
java.util.regex.Matcher m_script;
java.util.regex.Pattern p_style;
java.util.regex.Matcher m_style;
java.util.regex.Pattern p_html;
java.util.regex.Matcher m_html;
try {
String regEx_script = "<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?script[\\s]*?>"; //定义script的正则表达式{或<script[^>]*?>[\\s\\S]*?<\\/script> }
String regEx_style = "<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>"; //定义style的正则表达式{或<style[^>]*?>[\\s\\S]*?<\\/style> }
String regEx_html = "<[^>]+>"; //定义HTML标签的正则表达式
p_script = Pattern.compile(regEx_script,Pattern.CASE_INSENSITIVE);
m_script = p_script.matcher(htmlStr);
htmlStr = m_script.replaceAll(""); //过滤script标签
p_style = Pattern.compile(regEx_style,Pattern.CASE_INSENSITIVE);
m_style = p_style.matcher(htmlStr);
htmlStr = m_style.replaceAll(""); //过滤style标签
p_html = Pattern.compile(regEx_html,Pattern.CASE_INSENSITIVE);
m_html = p_html.matcher(htmlStr);
htmlStr = m_html.replaceAll(""); //过滤html标签
textStr = htmlStr;
}catch(Exception e) {
System.err.println("Html2Text: " + e.getMessage());
}
return textStr;//返回文本字符串
}
相关推荐
NULL 博文链接:https://jiangtie.iteye.com/blog/1003878
NULL 博文链接:https://vb2005xu.iteye.com/blog/387621
NULL 博文链接:https://gwh-08.iteye.com/blog/2241020
NULL 博文链接:https://jacky-dai.iteye.com/blog/2314511
NULL 博文链接:https://mengyang.iteye.com/blog/575671
http://www.iteye.com/topic/699515 主题:Swing是一把刀 http://www.iteye.com/topic/702804 主题:Swing第二刀:枝间新绿一重重 http://www.iteye.com/topic/707540 主题:Swing第二小刀刀:星星之火可以燎原 ...
NULL 博文链接:https://xuhu-java.iteye.com/blog/1136453
NULL 博文链接:https://hw1287789687.iteye.com/blog/1936364
java SE7 虚拟机规范,非官方翻译。 原文地址:http://icyfenix.iteye.com/blog/1256329
NULL 博文链接:https://t240178168.iteye.com/blog/1660452
NULL 博文链接:https://smallratluobin.iteye.com/blog/2089269
从零开始学Spring Boot,没有积分的可以看博客:http://412887952-qq-com.iteye.com/ 【Spring Boot 系列博客】 0)前言【从零开始学Spring Boot】 : http://412887952-qq-com.iteye.com/blog/2291496 (1...
NULL 博文链接:https://da-zhuang.iteye.com/blog/2234078
NULL 博文链接:https://xieyan30.iteye.com/blog/1695483
NULL 博文链接:https://978182241.iteye.com/blog/1827062
博文链接:https://qarqan.iteye.com/blog/105844
NULL 博文链接:https://chinrui.iteye.com/blog/1859820
NULL 博文链接:https://michaelzqm.iteye.com/blog/910077
NULL 博文链接:https://jianfeihit.iteye.com/blog/1835272
NULL 博文链接:https://jinjiajie.iteye.com/blog/999217