Here you can find the source of replaceAll(String string, Pattern pattern, String repalStr)
public static String replaceAll(String string, Pattern pattern, String repalStr)
//package com.java2s; //License from project: Open Source License import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static String replaceAll(String string, Pattern pattern, String repalStr) { if (string == null) { return null; }/* w w w .j av a 2 s. c o m*/ Matcher m = pattern.matcher(string); if (m.find()) { StringBuffer sb = new StringBuffer(); while (true) { m.appendReplacement(sb, repalStr); if (!m.find()) { break; } } m.appendTail(sb); return sb.toString(); } return string; } }