Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript regular expression to find table names with alias in SQL code

I have a very large SQL query. I am trying to scrape tables names using javascript out of SQL query. (I provide SQL query in a text file as input)

  select t1.name, t1.id, t1.address, t2.units,t2.sale
  from SCHMEA1.candy_customers_azim_056 as t1
  inner join SCHEMA1.candy_sales_history_set t2
    on (t1.custid = t2.ORIGTN_ACCT_NO)

What could be the regular expression to achieve something like this ?

Tables:
candy_customers_azim_056 as t1
candy_sales_history_set t2
like image 496
Azim Shaik Avatar asked Jul 20 '26 16:07

Azim Shaik


1 Answers

(from|join)\s+\w+\.((\w*)[as ]+(\w+))

should return what you're looking for in the second capture group.

like image 67
user8675309 Avatar answered Jul 23 '26 05:07

user8675309



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!