微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

替换string中的部分字符串 关键时候还得正则出马

String startRegex = "(<|<f|<fo|<fon|<font|<font |<font c|<font co|<font col|<font colo|<font color|<font color=|<font color='|<font color='r|<font color='re|<font color='red|<font color='red'|<font color='red'>|<font color='red'>)$";
Pattern pat = Pattern.compile(startRegex);
Matcher matcher = pat.matcher(content);
while (matcher.find()) {
content = content.replaceAll(startRegex,"");
}

String endRegex = "(</f|</fo|</fon|</font)$";
Pattern pat1 = Pattern.compile(endRegex);
Matcher matcher1 = pat1.matcher(content);
while (matcher1.find()) {
content = content.replaceAll(endRegex,"</font>");
}

String regex = "(<font color='red'>.*)$"; Pattern pat2 = Pattern.compile(regex); Matcher matcher2 = pat2.matcher(content); while (matcher2.find()) { content = content + "</font>"; }

原文地址:https://www.jb51.cc/regex/358674.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐