/** * Executes this placeholder for the given {@link String} by searching all occurrences of the regular expression * supplied in the constructor and replaces them with the retrieved replacement from * {@link #getReplacementFor(String, ReplacementData)}. If the regular expression does not match, an exact copy of * the given {@link String} is returned. * * @param data used to process given {@code formatPattern} * @param formatPattern to be processed * @return the given {@code formatPattern} containing the generated replacements instead of matching patterns */ public String process(ReplacementData data, String formatPattern) { StringBuffer sb = new StringBuffer(); Matcher matcher = pattern.matcher(formatPattern); while (matcher.find()) { matcher.appendReplacement(sb, Matcher.quoteReplacement(getReplacementFor(matcher.group(), data))); } matcher.appendTail(sb); return sb.toString(); }