Alex Rivera | Logout

Using Regex to extract table names from a file containing SQL queries

Asked 2010-11-18T11:02:18.333
11

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?

Edit
Report

1 Answer

11

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

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

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.

answered 2010-11-18T11:17:45.063

Your Answer