考虑以下查询:
select
foo,
bar,
yourmom
from
theTable
select top 10 *
from
theTable
select distinct foo, bar + 1, yourmom from theTable
我想要一个可以提取的正则表达式查询:
foo,
bar,
yourmom
*
foo, bar + 1, yourmom
分别。
我尝试了 ^\sselect\s(distinct\s)?(top\s\d*)?(?'columns'.*\s)from[\s.]*$
,我认为这会起作用,但不会。我已经玩了一段时间了,但我仍然无法在所有三个测试用例中使用它。有人可以帮我解决他们的 regex-fu 问题吗?
最佳答案
编辑:首先,您需要使 .- 匹配每个字符,包括换行符。在 Java 中,您可以设置 DOTALL 标志,但在 C# 中,我相信您应该使用 RegexOptions.SingleLine
选项。
那么这个表达式应该有效:
^\s*select\s+(?:distinct\s+)?(?:top\s+\d*\s+)?(?'columns'.*?)from.*$
关于c# - 用于从 SQL 查询中提取列定义的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10212855/