标签:comm regex char try tostring com pat input keyword
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();
}
标签:comm regex char try tostring com pat input keyword
原文地址:http://www.cnblogs.com/sunshisonghit/p/7218866.html