`

正则表达式解析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]);
   }

 }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics