Here you can find the source of replaceAllBackreference(String text, String regex, String replacement)
public static String replaceAllBackreference(String text, String regex, String replacement)
//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 replaceAllBackreference(String text, String regex, String replacement) { Matcher m = createMatcher(text, regex); text = m.replaceAll(replacement); return text; }//from w ww .ja v a2s . co m /** * Given a regex and an input, returns a matcher to match the regex to the * input * * @param regex * the regular expression * @param input * the input char sequence * @return the matcher */ public static Matcher createMatcher(CharSequence input, String regex) { Pattern p = Pattern.compile(regex); Matcher m = p.matcher(input); return m; } }