将
o.a =[' 1' ] and b.i = [2] and c.y = ['9'] order by o.d desc, i.r asc, u.d这样的语句,变成:o.a =? and b.i = ? and c.y =? order by o.d desc, i.r asc, u.d也就是,将每个 [ ] 这样的东东使用 ?号替换掉。
o.a =[' 1' ] and b.i = [2] and c.y = ['9'] order by o.d desc, i.r asc, u.d这样的语句,变成:o.a =? and b.i = ? and c.y =? order by o.d desc, i.r asc, u.d也就是,将每个 [ ] 这样的东东使用 ?号替换掉。
String result = test.replaceAll("\\[[^\\[\\]]*\\]", "?");
System.out.println(result);
那么直接开头为‘【’,结尾为‘】’的内容转化为‘?’即可;
代码如下
str = str.replaceAll("^[\\[]*\\]]$", "?");
String test = "o.a =[' 1' ] and b.i = [2] and c.y = ['9'] order by o.d desc, i.r asc, u.d";
String result = test.replaceAll("(?isn)(?<a>=\s*).+?(?=(and|order))", "${a}? ");
System.out.println(result);
嘿嘿,客客师傅。