java中正则表达对特殊字符进行转义处理代码

public static String escapeExprSpecialWord(String keyword) {    
   if (keyword != "") {    
       String[] fbsArr = { "\\", "$", "(", ")", "*", "+", ".", "[", "]", "?", "^", "{", "}", "|" };    
       for (String key : fbsArr) {    
           if (keyword.contains(key)) {    
               keyword = keyword.replace(key, "\\" + key);    
           } 
       }    
   }    
   return keyword;  
}    


public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("hello world");
String key="FID_MESSAGE";
String value="该产品首次认购金额不得低于(收益凭证类):50000";
String value1 = escapeExprSpecialWord(value);

String a = "FID_MESSAGE=该产品首次认购金额不得低于(收益凭证类):50000";
Pattern pattern = Pattern.compile(key + "\\s*=\\s*" + value1);
Matcher m = pattern.matcher(a);
while (m.find()) {
System.out.println(m.group());

你可能感兴趣的:(4-java)