Text Processingflags: gis
SQL SELECT Statement
Match the column list and table name from a SQL SELECT ... FROM statement.
Try it in RegexPro →Available in
Pattern
regexengine-agnostic
SELECT\s+(.+?)\s+FROM\s+([\w."`\[\]]+) (flags: gis)Raw source: SELECT\s+(.+?)\s+FROM\s+([\w."`\[\]]+)
How it works
SELECT\s+ matches the keyword and required whitespace. (.+?) lazily captures the column list. \s+FROM\s+ matches the FROM keyword. ([\w."`\[\]]+) captures the table identifier including dots (db.schema.table), and the three quoting styles SQL dialects use: "double", `backtick`, [bracket]. Flags: g (global), i (case-insensitive SELECT/FROM), s (dotAll so columns can span newlines).
Examples
Input
SELECT id, name FROM usersMatches
SELECT id, name FROM users
Input
select * from `orders`Matches
select * from `orders`
Input
INSERT INTO logsNo match
—Common use cases
- •SQL parsing in lint / formatter tooling
- •Extracting referenced tables from migration files
- •Query observability — surfacing what tables a service hits
- •ORM-vs-raw-SQL audit scripts