( ( warehouse_code LIKE 'TEST' )
 
 AND ( ( cust_code LIKE 'SIN000135' )
  
  OR ( cust_code LIKE 'SIN000007' )
 
  OR ( cust_code LIKE 'SIN000010' ) )
 
  OR ( warehouse_code LIKE 'UWSFO' )
  
 AND ( ( cust_code LIKE 'SIN000175' )
  
  OR ( cust_code LIKE 'SIN000170' ) ) )
我想把上面的变成下面的,是可以用正则表达式么,还有什么比较好又快的办法?各位大家前来指点迷津!
  ( ( warehouse_code LIKE 'TEST' )   AND ( ( 1=1 )
 
  OR ( 1=1 )

 OR (1=1) )

 OR ( warehouse_code LIKE 'UWSFO' )

AND ( ( 1=1 )
 
 OR ( 1=1) ) )

解决方案 »

  1.   

        String str = "AND   (   (   cust_code   LIKE   'SIN000135'   ) ";
        System.out.println(str.replaceAll("\\([^(]*?\\)", "(1=1)"));
      

  2.   

    String input = "cust_code   LIKE   'SIN000135'";
    String result = input.replaceAll("cust_code   LIKE\\s+'.+'", "1=1");
    System.out.println(result);
    /*1=1*/
      

  3.   

    1)
    String str =the  above string ;
        System.out.println(str.replaceAll("\\([^(]*?\\)", "(1=1)"));
    结果是
    (   (1=1) AND   (   (1=1)  OR   (1=1)  OR   (1=1)   )  OR   (1=1) AND   (   (1=1)   OR   (1=1)   )   ) 
    把warehouse and  cust-code 都变成1=1了。2)
    String str =the  above string ;
    String result = input.replaceAll("cust_code   LIKE\\s+'.+'", "1=1");
    System.out.println(result);
    结果是
    (   (   warehouse_code   LIKE   'TEST'   ) AND   (   (   1=1   )   )   ) 没有后面的内容了。谢谢各位的及时回答,不过我想知道一大串字符串的转换,盼望解答。
    对于正则表达式我知道的太少了。大家给我指个方向。
      

  4.   

    不好意思 用了贪婪匹配了
    try thisString result = input.replaceAll("cust_code   LIKE\\s+'.*?'", "1=1");
      

  5.   

        String str = "AND   (   (   cust_code   LIKE   'SIN000135'   ) AND (   warehouse_code   LIKE   'TEST'   )  ";
        System.out.println(str.replaceAll("\\(\\s*cust_code\\s*LIKE.*?\\)", "(1=1)"));