Html常见符号字符的匹配和替换

Html常见符号字符

符号 含义 html
= 等于 eq
!= 不等于 ne,neq
> 大于 qt
< 小于 lt
>= 大于等于 gte,ge
<= 小于等于 lte,le
! not

过滤工具类方法

/** * Parse Html to Text * * @author xuzhou * @version 1.0.0 * @title HtmlParseUtils * @date 2021/1/21 17:41 */
public class HtmlParseUtils {
   

    /** * Html标签 * < > */
    private static final String HTML_REG = "<[^>]+>";
    /** * &nbsp; -> " " */
    private static final String HTML_SPACE = "&nbsp;";
    private static final String HTML_SPACE_REPLACE = " ";
    /** * &amp; -> & */
    private static final String HTML_AND = "&amp;";
    private static final String HTML_AND_REPLACE = "&";
    /** * &lt; -> < */
    private static final String HTML_MORE = "&lt;";
    private static final String HTML_MORE_REPLACE = "<";
    /** * &gt; -> > */
    private static final String HTML_LESS = "&gt;";
    private static final String HTML_LESS_REPLACE = ">";
    /** * &quot; -> ” */
    private static final String HTML_DOUBLE_QUOTES = "&quot;";
    private static final String HTML_DOUBLE_QUOTES_REPLACE = "\"";
    /** * &qpos; -> ‘ */
    private static final String HTML_APOSTROPHE = "&qpos;";
    private static final String HTML_APOSTROPHE_REPLACE = "'";

    private HtmlParseUtils() {
   

    }

    public static String htmlPares(String str) {
   
        if (StringUtils.isBlank(str)) {
   
            return StringUtils.EMPTY;
        }

        return str.replaceAll(HTML_REG, StringUtils.EMPTY)
                .replace(HTML_SPACE, HTML_SPACE_REPLACE)
                .replace(HTML_AND, HTML_AND_REPLACE)
                .replace(HTML_MORE, HTML_MORE_REPLACE)
                .replace(HTML_LESS, HTML_LESS_REPLACE)
                .replace(HTML_DOUBLE_QUOTES, HTML_DOUBLE_QUOTES_REPLACE)
                .replace(HTML_APOSTROPHE, HTML_APOSTROPHE_REPLACE);

    }
}
全部评论

相关推荐

Java抽象带篮子:难蚌,点进图片上面就是我的大头😆
点赞 评论 收藏
分享
找不到工作死了算了:没事的,雨英,hr肯主动告知结果已经超越大部分hr了
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务