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 { public static String replaceAll(String str, String regex, String replacement) { Pattern p = Pattern.compile(regex); Matcher m = p.matcher(str); StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, replacement); }/*from ww w. j a v a 2s . c o m*/ m.appendTail(sb); return sb.toString(); } }