普通EX pression找到查询中所有表名普通、EX、pression

2023-09-02 01:50:50 作者:是谁浮了流年

我不是那个炎热的定期EX pressions,它使我的一点心意融化了一些什么。

I am not that hot at regular expressions and it has made my little mind melt some what.

我试图找到一个查询中所有表的名称。所以说,我有查询:

I am trying to find all the tables names in a query. So say I have the query:

SELECT one, two, three FROM table1, table2 WHERE X=Y

我想拉出来表1,表2或表1和表2

I would like to pull out "table1, table2" or "table1" and "table2"

但是,如果有什么,没有where语句。这可能是该文件的末尾,或者有可能是一组通过或等命令,我知道最的时候,这不会是一个问题,但我不喜欢编码最的想法的情况,知道我已经离开了,可能会导致事情错了后来去了一个洞。

But what if there is no where statement. It could be the end of the file, or there could be a group by or an order by etc. I know "most" of the time this will not be an issue but I don't like the idea of coding for "most" situations and knowing I have left a hole that could cause things to go wrong later.

这是一个可行的正则表达式EX pression?我是不是一个正则表达式pleb?

Is this a doable Regex expression? Am I being a Regex pleb?

(PS这将是在C#中,但presume是没有多大意义的完成)。

(P.S. this will be done in C# but presume that doesn't matter much).

感谢

乔恩

推荐答案

正则表达式是不是很擅长这一点,因为它的很多比它更复杂显示:

RegEx isn't very good at this, as it's a lot more complicated than it appears:

如果他们使用左/右内/外/ CROSS /合并/自然科学,而不是A,B语法加入?甲,乙语法应该是无论如何回避。 在什么嵌套查询? 如果没有表(选择一个常数) 在什么换行符和其他空白格式? 别名?

我可以继续下去。

你可以做的是寻找一个SQL语法分析程序,并通过运行查询。

What you can do is look for an sql parser, and run your query through that.