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
Related patterns
Python Import Statement
Text ProcessingMatch Python `import x` and `from x import y` statements, capturing the module and target.
Terraform Resource Block Header
Text ProcessingMatch the opening line of a Terraform `resource "type" "name" {` block, capturing the resource type and local name.
GraphQL Operation Header
Text ProcessingMatch GraphQL operation headers — `query`, `mutation`, or `subscription` — capturing the operation name.
HCL / Terraform Variable Reference
Text ProcessingMatch Terraform / HCL references like `var.name`, `local.foo`, `module.x.output`, or `data.aws_ami.ubuntu.id`.