Regular Expressions 101

Community Patterns

Extract columns names from any select query

1

Regular Expression
Golang

`
(?:\s+as\s+)(?P<renamed>\w+)|(?P<renamed_without_as>\s+\w+\,)|(?:^\s*\w+\.)(?P<original>\w+)(?:\,|from)
`
igm

Description

This regex can capture any column name from a select query.

Be the original name, like are named on table, renamed with a reserved word AS or even without explicit AS.

Go on, and test with your query ;)

Submitted by Jefferson Gouveia - 6 years ago