Here you can find the source of replaceAll(Pattern p, String s, String r, Function
Parameter | Description |
---|---|
p | The pattern to match on |
s | The input string |
r | The template of the replacement string |
cb | The callback that returns an array of objects to place into the template |
public static String replaceAll(Pattern p, String s, String r, Function<Matcher, Object[]> cb)
//package com.java2s; //License from project: Open Source License import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { /**/*from www . j a v a 2s . co m*/ * Replaces all occurrences of the pattern in this input * * @param p The pattern to match on * @param s The input string * @param r The template of the replacement string * @param cb The callback that returns an array of objects to place into the * template * @return a string will all matched patterns replaced */ public static String replaceAll(Pattern p, String s, String r, Function<Matcher, Object[]> cb) { Matcher m = p.matcher(s); while (m.find()) { s = m.replaceFirst(String.format(r, cb.apply(m))); m = p.matcher(s); } return s; } }