String str = "select a,  // 想要a
                     tbl.b, // 想要b
                     tbl.c d, // 想要d
                     decode(tbl.e, '1', 1, 0)  f // 想要f
              from sad tbl"
想把被搜索的项目名字提取出来

解决方案 »

  1.   


    你那个是从数据库里查找数据,
    String str = "select a,  // 想要a
                         tbl.b, // 想要b
                         tbl.c d, // 想要d
                         decode(tbl.e, '1', 1, 0)  f // 想要f
                  from sad tbl"
    pstmt=conn.preparedStatement(str);
    rs=p.executeQueary();
    //[a,b,d,f]{1,}找的是结构,而不是字段,我也不知道怎么解决,期待高手。
    Pattern p = Pattern.compile("[a,b,d,f]{1,}");
     Matcher m = p.matcher("aaaaab");
     boolean b = m.matches();
      

  2.   

    sorry,Matcher m = p.matcher("aaaaab"); 写错了,
    应该是Matcher m = p.matcher("str");
      

  3.   

    "select\\s(.*)\\stb1\\.(.*)…………"   调用里面的正则库就可以了,把要提取出来的用括号扩起来,用.group()就可以提取出来了,具体的你自己看看你的字符串是什么样子的,我仅仅写了前面的一点,。