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 = "<[^>]+>";
/** * -> " " */
private static final String HTML_SPACE = " ";
private static final String HTML_SPACE_REPLACE = " ";
/** * & -> & */
private static final String HTML_AND = "&";
private static final String HTML_AND_REPLACE = "&";
/** * < -> < */
private static final String HTML_MORE = "<";
private static final String HTML_MORE_REPLACE = "<";
/** * > -> > */
private static final String HTML_LESS = ">";
private static final String HTML_LESS_REPLACE = ">";
/** * " -> ” */
private static final String HTML_DOUBLE_QUOTES = """;
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);
}
}