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

首頁 > 編程 > Java > 正文

java 過濾html標簽

2019-11-06 06:10:12
字體:
來源:轉載
供稿:網友

去除html標簽,包括script、style,以及html字符&nbsp等

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標簽的正則表達式 String regEx_blank="&nbsp;|&quot;|&amp;|&lt;|&gt;";//定義html字符&nbsp;|&quot;|&amp;|&lt;|&gt; 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標簽 Pattern p_blank=Pattern.compile(regEx_blank,Pattern.CASE_INSENSITIVE); Matcher m_blank=p_blank.matcher(htmlStr); htmlStr=m_blank.replaceAll(""); //過濾;nbsp return htmlStr.trim(); //返回文本字符串 }
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 米脂县| 吉首市| 徐水县| 莱西市| 靖江市| 类乌齐县| 长宁县| 娄底市| 田林县| 北票市| 泉州市| 砚山县| 克什克腾旗| 个旧市| 荣成市| 建水县| 浙江省| 拉孜县| 琼海市| 东乡县| 巴楚县| 漳州市| 洛扎县| 威信县| 东明县| 河北省| 宁阳县| 镇康县| 佛山市| 平谷区| 镇赉县| 河北省| 云南省| 始兴县| 增城市| 新丰县| 钟山县| 拉萨市| 岳普湖县| 桐庐县| 铜陵市|