日期:2014-05-16 浏览次数:20578 次
select * from mtab select * from mtab where id=10 select * (select * from mmtab where id=10) where id=10 //取得 (select * from mmtab where id=10) select * (select * from mmtab where (id=10 and zz=5)) where id=10 //取得 (select * from mmtab where (id=10 and zz=5)) select * (select * from mmtab where (id=10 and zz=5)) where (id=10 zz=5) //取得 (select * from mmtab where (id=10 and zz=5)) select * (select * from mmtab where (id=10 and zz=5)) where (id=10 zz=5) order by id desc //取得 (select * from mmtab where (id=10 and zz=5))
var str = "select * (select * from mmtab where (id=10 and zz=5)) where (id=10 zz=5) order by id desc"; alert(str.match(/\(([^\(]*(\([^\)]*\))*)\)/)[1]);
------解决方案--------------------
一直想学正则,呵呵,帮顶了
------解决方案--------------------
LZ, 今天51回你,该快速结贴给分了,下面正则值多少分就给多少吧......
var str = "select * (select * from mmtab where (id=10 and zz=5)) where (id=10 zz=5) order by id desc"; alert(str.match(/\([^\)]+\)+/g)[0]);
------解决方案--------------------
<script> var arr=["select * from mtab", "select * from mtab where id=10", "select * (select * from mmtab where id=10) where id=10", //取得 (select * from mmtab where id=10) "select * (select * from mmtab where (id=10 and zz=5)) where id=10", //取得 (select * from mmtab where (id=10 and zz=5)) "select * (select * from mmtab where (id=10 and zz=5)) where (id=10 zz=5)", //取得 (select * from mmtab where (id=10 and zz=5)) "select * (select * from mmtab where (id=10 and zz=5)) where (id=10 zz=5) order by id desc"] //取得 (select * from mmtab where (id=10 and zz=5)) var reg=/(^select.*?)(\(?select.*\)?)(where.*?$)/ig; for(var i=0;i<arr.length;i++) document.write(arr[i].replace(reg,"$2")+"<br>"); </script>
------解决方案--------------------
又来看看,还没有得分啊。楼上的朋友,如果字串中没有“select.*”怎么办呢?正则的实质是最大限度抽象和简洁。
<script> var arr=["select * from mtab", "select * from mtab where id=10", "select * (select * from mmtab where id=10) where id=10", //取得 (select * from mmtab where id=10) "select * (select * from mmtab where (id=10 and zz=5)) where id=10", //取得 (select * from mmtab where (id=10 and zz=5)) "select * (select * from mmtab where (id=10 and zz=5)) where (id=10 zz=5)", //取得 (select * from mmtab where (id=10 and zz=5)) "select * (select * from mmtab where (id=10 and zz=5)) where (id=10 zz=5) order by id desc"] //取得 (select * from mmtab where (id=10 and zz=5)) var reg=/\([^\)]+\)+/g; for(var i=0;i<arr.length;i++) ! arr[i].match(reg) || document.write(arr[i].match(reg)[0]+"<br>"); </script>