Is there a regex which extracts SQL queries from a string? I\'m NOT interested to validate any SQL syntax, rather and only extracting a selection o
SQL is complicated enough that you will need context to find all statements, meaning that you can't do this with a regular expression.
For example:
SELECT Model FROM Product
WHERE ManufacturerID IN (SELECT ManufacturerID FROM Manufacturer
WHERE Manufacturer = 'Dell')
(example comes from http://www.sql-tutorial.com/sql-nested-queries-sql-tutorial/). Nested queries can be nested multiple times, start with different values, etc. If you could write a regular expression for the subset you are interested in, it would be unreadable.
ANTLR has a SQL 2003 grammar available (I haven't tried it).