生成正则表达式以匹配SQL Server select语句

时间:2018-02-14 08:17:11

标签: .net regex

我需要创建一个正则表达式来匹配SQL Server的select查询语法。以下是从msdn:

获取的查询结构
[ WITH { [ XMLNAMESPACES ,] [ <common_table_expression> [,...n] ] } ]  
    <query_expression>   
    [ ORDER BY { order_by_expression | column_position [ ASC | DESC ] }   
  [ ,...n ] ]   
    [ <FOR Clause>]   
    [ OPTION ( <query_hint> [ ,...n ] ) ]   
<query_expression> ::=   
    { <query_specification> | ( <query_expression> ) }   
    [  { UNION [ ALL ] | EXCEPT | INTERSECT }  
        <query_specification> | ( <query_expression> ) [...n ] ]   
<query_specification> ::=   
SELECT [ ALL | DISTINCT ]   
    [TOP ( expression ) [PERCENT] [ WITH TIES ] ]   
    < select_list >   
    [ INTO new_table ]   
    [ FROM { <table_source> } [ ,...n ] ]   
    [ WHERE <search_condition> ]   
    [ <GROUP BY> ]   
    [ HAVING < search_condition > ]

我需要制作一个正则表达式,它可以匹配使用上述语法编写的任何选择查询。

我创建了以下正则表达式,但它没有达到标准。在where子句之后,它匹配所有内容。 https://regexr.com/3kp3g

请帮忙

0 个答案:

没有答案