Pattern p = Pattern.compile("<c[w|r|g|y]>.*</c[w|r|g|y]>",Pattern.DOTALL);
Matcher m = p.matcher("<cw>白色字体</cw><cr>红色字体</cr>");
String s = "";
while(m.find()){
s = m.group();
}
//后面的?表示非贪婪匹配
s = s.replaceAll("<.*?>", "");
System.out.println(s);
本文介绍了一种使用Java正则表达式的方法来去除字符串中的HTML标签。通过Pattern和Matcher类的应用,实现对特定HTML标签的匹配与替换,最终输出纯文本内容。
170万+

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



