mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
增加HtmlUtil.cleanEmptyTag方法(pr#3838@Github)
This commit is contained in:
@@ -41,6 +41,10 @@ public class HtmlUtil {
|
||||
* HTML标签正则
|
||||
*/
|
||||
public static final Pattern RE_HTML_MARK = Pattern.compile("(<[^<]*?>)|(<\\s*?/[^<]*?>)|(<[^<]*?/\\s*?>)", Pattern.CASE_INSENSITIVE);
|
||||
/**
|
||||
* 正则:匹配空标签
|
||||
*/
|
||||
public static final String RE_HTML_EMPTY_MARK = "<(\\w+)([^>]*)>\\s*</\\1>";
|
||||
/**
|
||||
* script标签正则
|
||||
*/
|
||||
@@ -111,6 +115,17 @@ public class HtmlUtil {
|
||||
return ReUtil.replaceAll(content, RE_HTML_MARK, StrUtil.EMPTY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除所有HTML空标签<br>
|
||||
* 例如:{@code <p></p>}
|
||||
*
|
||||
* @param content 文本
|
||||
* @return 清除空标签后的文本
|
||||
*/
|
||||
public static String cleanEmptyTag(final String content) {
|
||||
return content.replaceAll(RE_HTML_EMPTY_MARK, StrUtil.EMPTY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除所有script标签,包括内容
|
||||
*
|
||||
|
Reference in New Issue
Block a user