国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > WEB開發(fā) > 正文

java過濾html標(biāo)簽獲取純文本信息

2024-04-27 15:16:59
字體:
供稿:網(wǎng)友
package com.lyt.base.util;import java.util.regex.Pattern;public class FilterHtmlUtil {public static String Html2Text(String inputString){    String htmlStr = inputString; //含html標(biāo)簽的字符串    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的正則表達(dá)式{或<script[^>]*?>[//s//S]*?<///script> }         String regEx_style = "<[//s]*?style[^>]*?>[//s//S]*?<[//s]*?///[//s]*?style[//s]*?>"; //定義style的正則表達(dá)式{或<style[^>]*?>[//s//S]*?<///style> }         String regEx_html = "<[^>]+>"; //定義HTML標(biāo)簽的正則表達(dá)式         p_script = Pattern.compile(regEx_script,Pattern.CASE_INSENSITIVE);         m_script = p_script.matcher(htmlStr);         htmlStr = m_script.replaceAll(""); //過濾script標(biāo)簽         p_style = Pattern.compile(regEx_style,Pattern.CASE_INSENSITIVE);         m_style = p_style.matcher(htmlStr);         htmlStr = m_style.replaceAll(""); //過濾style標(biāo)簽         p_html = Pattern.compile(regEx_html,Pattern.CASE_INSENSITIVE);         m_html = p_html.matcher(htmlStr);         htmlStr = m_html.replaceAll(""); //過濾html標(biāo)簽         textStr = htmlStr;    }catch(Exception e){    e.PRintStackTrace();    }    return textStr;//返回文本字符串} }
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 枣庄市| 双牌县| 南宫市| 海淀区| 岱山县| 曲阳县| 大丰市| 张家口市| 新乡县| 武功县| 渑池县| 墨竹工卡县| 兰考县| 巧家县| 光泽县| 祁东县| 桃园县| 左权县| 克拉玛依市| 汉源县| 许昌县| 达尔| 宁明县| 鹤壁市| 武山县| 九龙坡区| 太仆寺旗| 平泉县| 东方市| 仁寿县| 英超| 将乐县| 宁河县| 陈巴尔虎旗| 吉林省| 三河市| 永康市| 西林县| 孙吴县| 天柱县| 孟连|