正则表达式解析select与from之间

解析sql

public static void main(String[] args) {
   String str="select id as a1  , locationid as a2, user_sex as a3 from";
   Pattern p= Pattern.compile("\\w+\\s+as\\s+\\w+");//只兼容英文

 Pattern p= Pattern.compile("\\w+\\s+as\\s+[\\w[\u4E00-\u9FFF]]+");//兼容中英文
   Matcher m= p.matcher(str);
   while(m.find()){
   String tt=m.group();
   //System.out.println(tt);
   String[] sry= tt.split("\\s+as\\s+");
  // String[] sry=tt.split("as");
  
   System.out.println(sry[0]+sry[1]);
   }

 }

猜你喜欢

转载自helloworlda.iteye.com/blog/2223115
今日推荐