### Question:
TemplateMatcher { public String replace(CharSequence input, VariableResolver resolver){ StringBuilder buff = new StringBuilder(); Matcher matcher = pattern.matcher(input); int cursor = 0; while(cursor<input.length() && matcher.find(cursor)){ buff.append(input.subSequence(cursor, matcher.start())); String value = resolver.resolve(matcher.group(1)); buff.append(value!=null ? value : matcher.group()); cursor = matcher.end(); } buff.append(input.subSequence(cursor, input.length())); return buff.toString(); } TemplateMatcher(String leftBrace, String rightBrace);  TemplateMatcher(String prefix); String replace(CharSequence input, VariableResolver resolver); String replace(String input, final Map<String, String> variables); void replace(Reader reader, Writer writer, VariableResolver resolver); void replace(Reader reader, Writer writer, Map<String, String> variables);  }### Answer:
@Test public void test() { String test1 = (new TemplateMatcher("${", "}").replace("this is ${santhosh}ghgjh\n ${kumar} sdf ${tekuri}abc", new VariableResolver(){ @Override public String resolve(String variable){ if(variable.equals("santhosh")) return null; return variable.toUpperCase(); } })); assertTrue(test1.equals("this is ${santhosh}ghgjh\n KUMAR sdf TEKURIabc")); String test2 = (new TemplateMatcher("$").replace("this is $santhosh ghgjh\n $kumar sdf $tekuri\n$ abc", new VariableResolver(){ @Override public String resolve(String variable){ return variable.toUpperCase(); } })); assertTrue(test2.equals("this is SANTHOSH ghgjh\n KUMAR sdf TEKURI\n abc")); }