且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从字符串中删除 HTML 标记

更新时间:2023-08-16 20:58:58

Use a HTML parser instead of regex. This is dead simple with Jsoup.

public static String html2text(String html) {
    return Jsoup.parse(html).text();
}

Jsoup also supports removing HTML tags against a customizable whitelist, which is very useful if you want to allow only e.g. <b>, <i> and <u>.

See also: