Here you can find the source of replaceAll(String regex, String str, Map
public static String replaceAll(String regex, String str, Map<String, String> map)
//package com.java2s; //License from project: Apache License import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static String replaceAll(String regex, String str, Map<String, String> map) { String replacement = null; Matcher m = Pattern.compile(regex).matcher(str); if (m.find()) { replacement = map.get(m.group(1)); }//from w w w .j av a 2 s .c o m return m.replaceAll(replacement); } }