Java正则替换图片base64 为 图片链接
public static void test34() throws IOException {
String str = "<p align=\"\" style=\"margin-top: 0px; text-indent: 2em; text-align: justify; font-size: 16pt;\">xx。<o:p></o:p></p>\n<p style=\"margin-top: 0px; text-align: center; font-size: 16pt;\"><img src=\"data:image/jpeg;base64,fhtykrglkfgfk774747474747474555465465ftgjhjgnghjnmgh\" data-originalurl=\"/xx/87f5444c6e2e4c4ea9a6e065d0164085.jpg\" hspace=\"\" border=\"0\" align=\"center\"></p>\n<p align=\"\" style=\"margin-top: 0px; text-indent: 2em; text-align: justify; font-size: 16pt;\">xx。<o:p></o:p></p>\n<p style=\"margin-top: 0px; text-align: center; font-size: 16pt;\"><img src=\"data:image/png;base64,hgjkgujgjhbjkjhkjh2345346464165gbjgbkjhjbkhk\" data-originalurl=\"/mongo2/3f6093accd494704bcb6c5cc3df16706.jpg\" hspace=\"\" border=\"0\" align=\"center\"></p>\n<p align=\"\" style=\"margin-top: 0px; text-indent: 2em; text-align: justify; font-size: 16pt;\">xx。<o:p></o:p></p>\n<p align=\"\" style=\"margin-top: 0px; text-indent: 2em; text-align: justify; font-size: 16pt;\">xx<o:p></o:p></p>\n<p align=\"\" style=\"margin-top: 0px; text-indent: 2em; text-align: justify; font-size: 16pt;\">xx<o:p></o:p></p>\n<p align=\"\" style=\"margin-top: 0px; text-indent: 2em; text-align: justify; font-size: 16pt;\">xx<o:p></o:p></p>";
String regex = "<img src=\"data:image/(\\S+);base64,(\\S+)\"";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
String key = matcher.group(2);
System.out.println("key:==========="+key);
String base64 = matcher.group(1)+ "88888888888888888888888888888888888";
matcher.appendReplacement(sb, "<img src=\""+base64+"\"");
}
matcher.appendTail(sb);
System.out.println("Contents of the StringBuffer: \n"+ sb.toString() );
}