Java的方式向HTML形式的字符串中指定位置插入信息

来源:互联网 发布:c语言swap 编辑:程序博客网 时间:2024/06/03 13:40
public String setNewDescription(String descriptions) {
String message = "this is message";
Pattern filter = Pattern.compile("<div class=\"item-description\".*?>[\\s\\S]*?</div>", Pattern.CASE_INSENSITIVE);
Matcher filterMatcher = filter.matcher(descriptions);
String content = null;
if(filterMatcher.find()) {
content = filterMatcher.group();
}
StringBuffer sb = new StringBuffer(content);
sb.insert(content.lastIndexOf("</div>"), message);
return descriptions.replaceAll("<div class=\"item-description\".*?>[\\s\\S]*?</div>", sb.toString());
}
原创粉丝点击