Android Html 过滤标签

巴斯大学是一所以科研为向导的英国顶尖名校,科研实力被评定为世界领先。大学位于英格兰南部的世界遗产城市-巴斯,历年最高排名全英第4。巴斯大学管理学院在业界享有极高声誉。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

        String content="<div class=\\\"para\\\" label-module=\\\"para\\\" style=\\\"word-wrap: break-word; margin-bottom: 5px; zoom: 1;\\\">巴斯大学(University of Bath)<span style=\\\"position: relative; vertical-align: baseline; top: -0.5em; margin-left: 2px; cursor: default; padding-right: 2px; padding-left: 2px;\\\">[1]</span><a class=\\\"sup-anchor\\\" name=\\\"ref_[1]_16367\\\" style=\\\"position: relative; top: -50px;\\\">&nbsp;</a>&nbsp;是一所以科研为向导的英国顶尖名校,科研实力被评定为世界领先<span style=\\\"position: relative; vertical-align: baseline; top: -0.5em; margin-left: 2px; cursor: default; padding-right: 2px; padding-left: 2px;\\\">[2]</span><a class=\\\"sup-anchor\\\" name=\\\"ref_[2]_16367\\\" style=\\\"position: relative; top: -50px;\\\">&nbsp;</a>&nbsp;。</div><div class=\\\"para\\\" label-module=\\\"para\\\" style=\\\"word-wrap: break-word; margin-bottom: 5px; zoom: 1;\\\">巴斯大学是全英前10的著名学府,历年最高排名全英第4(分别于2003年和2015年)<span style=\\\"position: relative; vertical-align: baseline; top: -0.5em; margin-left: 2px; cursor: default; padding-right: 2px; padding-left: 2px;\\\">[3]</span><a class=\\\"sup-anchor\\\" name=\\\"ref_[3]_16367\\\" style=\\\"position: relative; top: -50px;\\\">&nbsp;</a>&nbsp;。成立于1966年,现任校监为女王<a target=\\\"_blank\\\" href=\\\"http://baike.baidu.com/view/47650.htm\\\">伊丽莎白二世</a>的三子 -&nbsp;<a target=\\\"_blank\\\" href=\\\"http://baike.baidu.com/subview/3035700/11062139.htm\\\" data-lemmaid=\\\"8488157\\\">爱德华王子</a>, 威塞克斯伯爵<span style=\\\"position: relative; vertical-align: baseline; top: -0.5em; margin-left: 2px; cursor: default; padding-right: 2px; padding-left: 2px;\\\">[4]</span><a class=\\\"sup-anchor\\\" name=\\\"ref_[4]_16367\\\" style=\\\"position: relative; top: -50px;\\\">&nbsp;</a>&nbsp;。</div><div class=\\\"para\\\" label-module=\\\"para\\\" style=\\\"word-wrap: break-word; margin-bottom: 5px; zoom: 1;\\\"><img src=\\\"http://g5bk.com:8080/MojieProject/file/smallContentFile/418ef337-8b48-4a2d-bf59-91f0a33259c3_47802525_5(1).jpg\\\" w=\\\"2599\\\" h=\\\"1640\\\" style=\\\"width: 778px;\\\"/><br></div><div class=\\\"para\\\" label-module=\\\"para\\\" style=\\\"word-wrap: break-word; margin-bottom: 5px; zoom: 1;\\\">大学位于<a target=\\\"_blank\\\" href=\\\"http://baike.baidu.com/view/58688.htm\\\">英格兰</a>南部的世界遗产城市-<a target=\\\"_blank\\\" href=\\\"http://baike.baidu.com/subview/89823/12443073.htm\\\" data-lemmaid=\\\"1620585\\\">巴斯</a>。根据英国各媒体近十年公布的英国大学排行榜,巴斯大学被稳固的确立为<span style=\\\"position: relative; vertical-align: baseline; top: -0.5em; margin-left: 2px; cursor: default; padding-right: 2px; padding-left: 2px;\\\">[3]</span><a class=\\\"sup-anchor\\\" name=\\\"ref_[3]_16367\\\" style=\\\"position: relative; top: -50px;\\\">&nbsp;</a>&nbsp;英国排行前十的大学。</div><div class=\\\"para\\\" label-module=\\\"para\\\" style=\\\"word-wrap: break-word; margin-bottom: 5px; zoom: 1;\\\"><a target=\\\"_blank\\\" href=\\\"http://baike.baidu.com/view/2416950.htm\\\">巴斯大学管理学院</a>被公认为英国最好的商学院之一,&nbsp;在业界有极高的声誉,每年有大量本科毕业生进入伦敦顶级投行工作,在2016年完全大学指南排名中位居第1位。</div><div class=\\\"para\\\" label-module=\\\"para\\\" style=\\\"word-wrap: break-word; margin-bottom: 5px; zoom: 1;\\\"><img src=\\\"http://g5bk.com:8080/MojieProject/file/smallContentFile/418ef337-8b48-4a2d-bf59-91f0a33259c3_slide1-large(1).jpg\\\" w=\\\"640\\\" h=\\\"480\\\" style=\\\"width: 640px;\\\"/><br></div><div class=\\\"para\\\" label-module=\\\"para\\\" style=\\\"word-wrap: break-word; margin-bottom: 5px; zoom: 1;\\\">巴斯大学在2015完全大学指南英国大学排名上��居第8位<span style=\\\"position: relat\n";


    /**
     * 定义script的正则表达式
     */
    private static final String REGEX_SCRIPT = "<script[^>]*?>[\\s\\S]*?<\\/script>";
    /**
     * 定义style的正则表达式
     */
    private static final String REGEX_STYLE = "<style[^>]*?>[\\s\\S]*?<\\/style>";
    /**
     * 定义HTML标签的正则表达式
     */
    private static final String REGEX_HTML = "<[^>]+>";
    /**
     * 定义空格回车换行符
     */
    private static final String REGEX_SPACE = "\\s*|\t|\r|\n";



    public static String delHTMLTag(String htmlStr) {
        // 过滤script标签
        Pattern p_script = Pattern.compile(REGEX_SCRIPT, Pattern.CASE_INSENSITIVE);
        Matcher m_script = p_script.matcher(htmlStr);
        htmlStr = m_script.replaceAll("");
        // 过滤style标签
        Pattern p_style = Pattern.compile(REGEX_STYLE, Pattern.CASE_INSENSITIVE);
        Matcher m_style = p_style.matcher(htmlStr);
        htmlStr = m_style.replaceAll("");
        // 过滤html标签
        Pattern p_html = Pattern.compile(REGEX_HTML, Pattern.CASE_INSENSITIVE);
        Matcher m_html = p_html.matcher(htmlStr);
        htmlStr = m_html.replaceAll("");
        // 过滤空格回车标签
        Pattern p_space = Pattern.compile(REGEX_SPACE, Pattern.CASE_INSENSITIVE);
        Matcher m_space = p_space.matcher(htmlStr);
        htmlStr = m_space.replaceAll("");




        Pattern a_space = Pattern.compile("&nbsp;", Pattern.CASE_INSENSITIVE);
        Matcher b_space = a_space.matcher(htmlStr);
        htmlStr = b_space.replaceAll("");


        return htmlStr.trim(); // 返回文本字符串
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值