例如这个SQL语句 select * from table left outer join table1 t1 on id1=xxid1 left outer join table2 t2 on id2=xxid2;
我用
String regex = "\\bjoin\\b?\\s" + TABLE_REGEX + "\\bon\\b";本想匹配2段 table1 t1 和 table2 t2
结果匹配到了 join "table1 t1 on id1=xxid1 left outer join table2 t2 " on看来是嵌套的问题,有没有正则表达式高手能解决我这个问题。
我用
String regex = "\\bjoin\\b?\\s" + TABLE_REGEX + "\\bon\\b";本想匹配2段 table1 t1 和 table2 t2
结果匹配到了 join "table1 t1 on id1=xxid1 left outer join table2 t2 " on看来是嵌套的问题,有没有正则表达式高手能解决我这个问题。
public static void testReg1(){
String ss="select * from table left outer join table1 t1 on id1=xxid1 left outer join table2 t2 on id2=xxid2";
String regex = "[.]*join ([^join^on]+) on ";
Pattern p=Pattern.compile(regex);
Matcher m=p.matcher(ss);
while(m.find()){
System.out.println(m.group(1));
}
}
输出结果:table1 t1
table2 t2记得那个非join,非On,否则就和你写的匹配结果一样了。
不过你看这样写的话,能蒙混过关不?
拿个分真不容易啊。String regex = "[.]*join ([^ ]+ [^ ]+) on ";
String regex = "\\bjoin\\b\\s" + "([^()^(\\Qjoin\\E)]+) " + "on";humanity的思路貌似更好,研究一下。
join ([^()]+)*? on"