I have a query :
select a.id, a.nama, b.alamat from tsql as a join tswl as b on a.id = b.id join tscl as c on a.id=c.id
And using regex I wanted to get only the table name from the query string.
I tried using the regular expression :
select.*from\s+(\w+).*join\s(\w+).*
Which managed to get the first table name after "from", but skipped the second table name, and get the third table name.
Current group :
[Group 1 : "tsql", Group 2 : "tscl"]
Targeted group : [Group 1 : "tsql", Group 2 : "tswl", Group 3 : "tscl"] ... and so on until the last name of the chain join query
Any help will be apreciated!
select.*from\s+(\w+)(?:.*?join\s(\w+))?(?:.*?join\s(\w+))?, you may repeat them as many times as you wish.