public static void main(String[] agrs){
String a ="one cat ${dog} cats ${in} the yard";
Map<String,String> map = new HashMap<>();
map.put("dog","dog1");
map.put("in","in1");
MenuTreeUtils.PatternUtils(a,map);
}
public static void PatternUtils(String a ,Map<String,String> map){
Pattern p = Pattern.compile("(\\$\\{)([\\w]+)(\\})");
Matcher m = p.matcher(a);
StringBuffer sb = new StringBuffer();
while (m.find()) {
String group = m.group(2);
m.appendReplacement(sb, map.get(group));
}
m.appendTail(sb);
System.out.println(sb.toString());
}