public
static
String transformMetachar(String input){
StringBuffer sb =
new
StringBuffer();
try
{
String regex =
"[+\-&|!(){}\[\]^"~*?:(\)\s]"
;
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(input);
while
(matcher.find()){
matcher.appendReplacement(sb,
"\\"
+matcher.group());
}
matcher.appendTail(sb);
}
catch
(Exception e){
//TODO
}
return
sb.toString();
}