去除:
String content = "<p><strong>啊啊啊。</strong></p><p><mark class="marker-yellow">不不不不</mark><s>不</s>,<i>发</i></p>"
// <p>段落替换为换行
content = content.replaceAll("<p .*?>", "\r\n");
// <br><br/>替换为换行
content = content.replaceAll("<br\\s*/?>", "\r\n");
// 去掉其它的<>之间的东西
content = content.replaceAll("\\<.*?>", "");
System.out.println(content);
结果:

需要清除富文本格式,找了一篇文章。感觉很好记录下。
原文地址
本文介绍了一个简单的Java代码片段,用于清除HTML标签,将<p>和<br>转换为换行符,从而实现从富文本中提取纯文本内容。这个方法适用于需要处理和清理HTML格式文本的场景。

1万+

被折叠的 条评论
为什么被折叠?



