用正则表达式会更复杂,因为没有很多个特定的匹配模式
你须抓select from , 这三个关键字
用indexof()即可
得到select from 的位置提取中间的字串 
再用,分割分别得到你所要的

解决方案 »

  1.   

    如果是select * from(select t1.c1,t2.c2 from table1 t1)t11 了,该怎么处理?
      

  2.   

    String str="select * from (select t1.c1,t2.c2 from (select t1.c1,t2.c2 from table1 t1 ))";
    while (str.indexOf("select")!=-1) {
    int start=str.indexOf("select")+7;
    int end=str.indexOf("from")-1;
    String out=str.substring(start,end);
    System.out.println("OUT:"+out);
    str=str.substring(str.indexOf("from")+4);
        }
    简单测试了一下 应该可以 但是前提是select 和from要配对的 否则就出错咯
      

  3.   

    只能满足
    statment: select <string> from statment
    如果有statment: select <string|statment> from statment 
    那就要复杂一点的算法 那还不如用正则表达式了 还可以把select 0这样的sql语句考虑进来也可以找出所有的select和from的index 然后一对一对按近距离的原则配对取数
      

  4.   

    select (.*) from table1 t1
    这样可以吧