I am looking for a regular expression to split a list of fields from an SQL SELECT statement.
I already retrieved the list of fields from the rest of the query, so I was left with a line that might look like this:
field1,field2,field3,CONCAT(field1,field2) AS concatted,IF(field1 = field2,field3,field4) AS logic
I think the logical approach would be to split the string into a comma if the comma doesn't appear in brackets, so I just need to find the correct regular expression for this ...?
The end result of what I'm trying to achieve is figuring out which fields seem to be direct selections from a table and which ones are made from SQL expressions, so that I can later decide whether to filter them using WHERE or HAVING.
Once I have a list of fields, I can check for the presence of the keyword "AS", which, although not perfect, should work with the way I write SQL.
( Bonus points , suggesting another way that differs between fields that are not expressions, but are an alias, and expressions that cannot be smoothed or can be, but without using "AS")
source share