Remove HTML tags from a String

后端 未结 30 3098
误落风尘
误落风尘 2020-11-21 07:35

Is there a good way to remove HTML from a Java string? A simple regex like

replaceAll("\\\\<.*?>", &quo         


        
30条回答
  •  终归单人心
    2020-11-21 07:59

    Sometimes the html string come from xml with such <. When using Jsoup we need parse it and then clean it.

    Document doc = Jsoup.parse(htmlstrl);
    Whitelist wl = Whitelist.none();
    String plain = Jsoup.clean(doc.text(), wl);
    

    While only using Jsoup.parse(htmlstrl).text() can't remove tags.

提交回复
热议问题