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());
java中正则表达对特殊字符进行转义处理代码
最新推荐文章于 2024-03-22 11:12:43 发布