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也就是,将每个 [  ] 这样的东东使用 ?号替换掉。

解决方案 »

  1.   

    str = str.replaceAll("\\[[^\\]]+\\]", "?");
      

  2.   

    try...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("\\[[^\\[\\]]*\\]", "?");
    System.out.println(result);
      

  3.   

    楼主只是要把【】内的东西转化为?
    那么直接开头为‘【’,结尾为‘】’的内容转化为‘?’即可;
    代码如下
    str = str.replaceAll("^[\\[]*\\]]$", "?");
      

  4.   


    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);
    嘿嘿,客客师傅。