java正则表达式替换[@more@]//正则表达式替换--尾部为空格或者;
String regex = "#w+((s)|(;)|()))";
Pattern pattern = pile(regex);
Matcher matcher = pattern.matcher(sql);
StringBuffer sbf = new StringBuffer();
while(matcher.find()){
//System.out.println(sql.substring(matcher.start()+1, matcher.end()-1));
//System.out.println(sql.substring(matcher.start()+1, matcher.end()-1).trim());
String argsValue = jbpmArgs.get(sql.substring(matcher.start()+1, matcher.end()-1).trim());
matcher.appendReplacement(sbf,argsValue);
sbf.append(" ");
}
matcher.appendTail(sbf);
sql = sbf.toString();
//正则表达式替换--尾部是字符串结尾
regex = "#w+($)";
pattern = pile(regex);
matcher = pattern.matcher(sql);
sbf = new StringBuffer();
while(matcher.find()){
//System.out.println(sql.substring(matcher.start()+1, matcher.end()));
//System.out.println(sql.substring(matcher.start()+1, matcher.end()).trim());
String argsValue = jbpmArgs.get(sql.substring(matcher.start()+1, matcher.end()).trim());
matcher.appendReplacement(sbf,argsValue);
sbf.append(" ");
}
matcher.appendTail(sbf);
sql=sbf.toString();
//正则表达式替换--尾部是括号的
regex = "#w+())";
pattern = pile(regex);
matcher = pattern.matcher(sql);
sbf = new StringBuffer();
while(matcher.find()){
//System.out.println(sql.substring(matcher.start()+1, matcher.end()));
//System.out.println(sql.substring(matcher.start()+1, matcher.end()).trim());
String argsValue = jbpmArgs.get(sql.substring(matcher.start()+1, matcher.end()-1).trim());
matcher.appendReplacement(sbf,argsValue);
sbf.append(" ) ");
}
matcher.appendTail(sbf);
sql=sbf.toString();
来自 “ ITPUB博客 ” ,链接:/25261409/viewspace-1058415/,如需转载,请注明出处,否则将追究法律责任。