I want to parse the Insert Query in Java using Regex.
Following is the sample string
INSERT INTO table_name (c1,c2,c3) VALUES (abc,def,ghi) , (jkl,mno,pqr)
I want the following output:
Group1: table_name
Group2: c1,c2,c3
Group3: abc,def,ghi
Group4: jkl,mno,pqr
I have tried the following regular Expression:
INSERT INTO ([A-Za-z][A-Za-z0-9_-]*) (?:\((.*)\))?\s*VALUES (\((,)?(.*)\))*
The output is
Group1 : table_name
Group2 : c1,c2,c3
Group3 : (abc,def,ghi) , (jkl,mno,pqr)
Group4 : Empty
Group5 : abc,def,ghi) , (jkl,mno,pqr
Please help me how to get the desired result.