大家好,又见面了,我是你们的朋友全栈君。
java正则表达式替换[@more@]//正则表达式替换–尾部为空格或者;
String regex = “#w+((s)|(;)|()))”;
Pattern pattern = Pattern.compile(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 = Pattern.compile(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 = Pattern.compile(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博客 ” ,链接:http://blog.itpub.net/25261409/viewspace-1058415/,如需转载,请注明出处,否则将追究法律责任。
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/145619.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...