sql语句段比如
where userid>10 and userid<20 order by id desc
因为有可能还有group by 如:
where userid>10 and userid<20 group by usertype order by id desc
或者group和order都没有 如:
where userid>10 and userid<20求问怎么用一条正则匹配出where条件,如上面的where userid>10 and userid<20如:Regex.Match("where userid>10 and userid<20 group by usertype order by id desc","待求正则表达式");匹配出where userid>10 and userid<20,注意上面说的可能出现的情况。谢了!
where userid>10 and userid<20 order by id desc
因为有可能还有group by 如:
where userid>10 and userid<20 group by usertype order by id desc
或者group和order都没有 如:
where userid>10 and userid<20求问怎么用一条正则匹配出where条件,如上面的where userid>10 and userid<20如:Regex.Match("where userid>10 and userid<20 group by usertype order by id desc","待求正则表达式");匹配出where userid>10 and userid<20,注意上面说的可能出现的情况。谢了!
而且写不写的出来还是一个问题,真写出来也是一个庞然大物,需要把所有的sql关键字、符号全考虑了。正则不是万能的。Sql解析器请参见:SQL Parser
By Serge Gorbenko
This article describes an implementation of a simple SQL parser which can be used to add or modify "where" and "order by" parts of SQL queries (PL/SQL).
http://www.codeproject.com/KB/dotnet/SQL_parser.aspx
如果这样的话,用正则是可以做到的
(?isn)where.+?(?=( group by|$))
正确的,我试了。不说啥了,我也写到(?isn)where.+?(?=( group by|order by))这了,没有想起来都没有的时候应该用$,牛兄就是牛。谢了