国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 白河县| 客服| 清水河县| 玛沁县| 会泽县| 灌云县| 临泽县| 星座| 江口县| 定南县| 吴堡县| 宿松县| 铜陵市| 海门市| 江城| 富顺县| 白河县| 星子县| 平谷区| 商都县| 荔波县| 和田市| 昆山市| 嘉荫县| 清流县| 原平市| 贺兰县| 绿春县| 精河县| 陆河县| 历史| 神农架林区| 黑水县| 曲麻莱县| 长海县| 迭部县| 灵宝市| 绥芬河市| 恭城| 潢川县| 小金县|