Here you can find the source of replaceAll(String str, String regex, String replacement)
public static String replaceAll(String str, String regex, String replacement)
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { /**//from ww w.ja v a 2s . com * Enhances the basic String#replaceAll method by including the Pattern.DOTALL bitmask in the replacement operation. */ public static String replaceAll(String str, String regex, String replacement) { StringBuffer sb = new StringBuffer(); try { Pattern pattern = Pattern.compile(regex, Pattern.DOTALL); Matcher matcher = pattern.matcher(str); while (matcher.find()) { matcher.appendReplacement(sb, replacement); } matcher.appendTail(sb); } catch (Exception ex) { } return sb.toString(); } }