日期:2014-05-20 浏览次数:20689 次
String sql="select a,b,c from abc where id=1 order by id desc"; String regex="\\bfrom\\s*\\S*"; Pattern p=Pattern.compile(regex); Matcher m=p.matcher(sql); if(m.find()){ String table=m.group().replace("from",""); System.out.println(""+table.trim()); }else{ System.out.println("not found"); }
------解决方案--------------------
String str="select a,b,c from abc where id=1 order by id desc";
Pattern p=Pattern.compile("(.*from\\s)(\\w*)(.*)");
Matcher m=p.matcher(str);
if(m.find()){
System.out.println(m.group(2));
}else{
System.out.println("false");
}