java去除字符串的html标签

Posted suruozhong

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java去除字符串的html标签相关的知识,希望对你有一定的参考价值。

//方法一
public String striphtml(String content) { 
    // <p>段落替换为换行 
    content = content.replaceAll("<p .*?>", "\r\n"); 
    // <br><br/>替换为换行 
    content = content.replaceAll("<br\\s*/?>", "\r\n"); 
    // 去掉其它的<>之间的东西 
    content = content.replaceAll("\\<.*?>", ""); 
    // 去掉空格 
   content = content.replaceAll(" ", "");
return content; } 方法二 public static String delHtmlTag(String str){ String newstr = ""; newstr = str.replaceAll("<[.[^>]]*>",""); newstr = newstr.replaceAll(" ", ""); return newstr; }

 


以上是关于java去除字符串的html标签的主要内容,如果未能解决你的问题,请参考以下文章