Hedgehog
Hedgehog

Reputation: 89

Regex to select column names from SQL query

I have a regexp that selects the columns from SQL query: \bwf\.[^,|^\s|^)]*

So from both queries

SELECT (wf.Name,
       wf.Status)

SELECT wf.Name, wf.Status

it will return "wf.Name", "wf.Status". But also I want to cover case when column contains round brackets:

SELECT (wf.Name,
       wf.Status())

regexp should return "wf.Name", "wf.Status()".

I tried to do it through non-capturing group (?:(?!\s|,|<statement>).)* but without success.

Upvotes: 2

Views: 1866

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626903

You can use

\bwf(?:\.\w+)+(?:\(\))?

See the regex demo. Details:

  • \b - a word boundary
  • wf - a wf string
  • (?:\.\w+)+ - one or more repetitions of a . and one or more word chars (?:\(\))? - an optional occurrence of a () substring.

Upvotes: 1

Related Questions