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

首頁 > 編程 > Java > 正文

Java中正則表達式去除html標簽

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

    注:這是java正則表達式去除html標簽方法。

    PRivate static final String regEx_script = "<script[^>]*?>[//s//S]*?<///script>"; // 定義script的正則表達式

    private static final String regEx_style = "<style[^>]*?>[//s//S]*?<///style>"; // 定義style的正則表達式    private static final String regEx_html = "<[^>]+>"; // 定義HTML標簽的正則表達式    private static final String regEx_space = "//s*|/t|/r|/n";// 定義空格回車換行符

    private static final String regEx_w = "<w[^>]*?>[//s//S]*?<///w[^>]*?>";//定義所有w標簽

/**     * @param htmlStr     * @return 刪除Html標簽     * @author LongJin     */    public static String delHTMLTag(String htmlStr) {        Pattern p_w = Pattern.compile(regEx_w, Pattern.CASE_INSENSITIVE);        Matcher m_w = p_w.matcher(htmlStr);        htmlStr = m_w.replaceAll(""); // 過濾script標簽        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_space = Pattern.compile(regEx_space, Pattern.CASE_INSENSITIVE);        Matcher m_space = p_space.matcher(htmlStr);        htmlStr = m_space.replaceAll(""); // 過濾空格回車標簽        htmlStr = htmlStr.replaceAll("&nbsp;", ""); //過濾&nbsp;        return htmlStr.trim(); // 返回文本字符串    }


上一篇:JAVA反射

下一篇:Java基礎語法

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 义马市| 遂川县| 宝兴县| 黄平县| 铅山县| 安义县| 措勤县| 贵阳市| 虹口区| 陈巴尔虎旗| 遵义县| 廊坊市| 资中县| 唐海县| 石渠县| 石楼县| 云龙县| 康平县| 钦州市| 攀枝花市| 金塔县| 繁峙县| 微山县| 大余县| 罗甸县| 宜君县| 阳新县| 安远县| 佳木斯市| 德庆县| 南通市| 陵水| 望江县| 安丘市| 轮台县| 汝城县| 社旗县| 尉氏县| 武平县| 民丰县| 文成县|