使用正则表达式提取包含SQL查询的文件表名 [英] Using Regex to extract table names from a file containing SQL queries

查看:1406
本文介绍了使用正则表达式提取包含SQL查询的文件表名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经含有大量的查询文本文件。我想在所有查询整个文件中使用的所有不同的表。表名可以在从或加入后,来了。我怎样才能做一个正则表达式匹配提取它们。任何人都可以提出一个正则表达式来获得比赛?

I've a text file containing large number of queries. I want to get all the distinct tables used in the entire file in all the queries. The table name can come after a 'from' or 'join'. How can i extract them by doing a regex match. Can anyone suggest a regular expression to get the matches?

推荐答案

这要看你的文件的结构。尝试使用这样的:

It depends on structure of your file. Try to use this:

(?<=from|join)(\s+\w+\b)

另外打开选项多行如果不分裂的阵列或单线字符串成员其他不便您的文件。
也尝试打开IgnorCase选项。

Also turn on options Multiline if your not split your file in array or smth else with singleline string members. Also try to turn on IgnorCase option.

这篇关于使用正则表达式提取包含SQL查询的文件表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆