62,614
社区成员
发帖
与我相关
我的任务
分享
String str="select a.f1,b.f2 from table1 a,table2 b where .....";
Pattern p=Pattern.compile(".*?from (.*?)( where|;)");//匹配"from "开头,到“ ”或者”;“结尾,加一个匹配 where就行了。
Matcher m = p.matcher(str);
while(m.find()){
System.out.println(m.group(1));
}
[/quote]
正则只学了个表面,对于一些特殊的限定方法还不是很清楚,谢谢了。
Pattern pattern = Pattern.compile("(from +(.*?)(;|where))");
Matcher matcher = pattern.matcher("select f1,f2 from table1,table2;");
// .matcher("select f1,f2 from table1 ,table2 where ……");
while (matcher.find()) {
String[] strs = matcher.group(2).split(",| +");
for (String str : strs) {
if (!str.equals("")) {
System.out.println(str.trim());
}
}
}
以前帮人做过类似的。
String str="select a.f1,b.f2 from table1 a,table2 b where .....";
Pattern p=Pattern.compile(".*?from (.*?)( where|;)");//匹配"from "开头,到“ ”或者”;“结尾,加一个匹配 where就行了。
Matcher m = p.matcher(str);
while(m.find()){
System.out.println(m.group(1));
}
String str="select f1,f2 from table1,table2 where .....";
Pattern p=Pattern.compile(".*?from (.*?)( |;)");//匹配"from "开头,到“ ”或者”;“结尾
Matcher m = p.matcher(str);
while(m.find()){
System.out.println(m.group(1));
}