http://repo.spring.io/libs-snapshot/org/apache/tomcat/embed/tomcat-embed-logging-juli/7.0.47/
public static void main (String args[]){
HashMap<String,String> map = new HashMap<String, String>();
map.put("*tt()","edit");
map.put("*u()","reduce");
String sourceString = "abcd*tt()uyuy*u()yuy";
String result = replaceString(sourceString, map);
System.out.println(result);
}
public static String replaceString(String sourceString, HashMap<String,String> map){
Iterator it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
String patternString = shieldSpecialSymboll((String)pair.getKey());
sourceString = sourceString.replaceAll(patternString, (String)pair.getValue());
it.remove();
}
return sourceString;
}
private static String shieldSpecialSymboll(String key) {
char[] sp = {'.','^','$','*','+','?'};
for (char ch : sp){
if (key.startsWith(String.valueOf(ch)))
key = "\\"+key;
}
return key;
}