I am trying to write a method that will accept a String, inspect it for instances of certain tokens (e.g. ${fizz}, ${buzz}, ${fo
Adapted from Matcher.replaceAll
boolean result = matcher.find();
if (result) {
StringBuffer sb = new StringBuffer();
do {
String tokenKey = matcher.group(1); // Ex: fizz
String replacement = Matcher.quoteReplacement(tokensMap.get(tokenKey));
matcher.appendReplacement(sb, replacement);
result = matcher.find();
} while (result);
matcher.appendTail(sb);
return sb.toString();
}