Eärion Eärion - 1 year ago 105
Java Question

get table name from query using a regex

I'm looking into finding a Pattern in order to get the table name for this type of SQL query;

INSERT INTO table(uuid,type) VALUES (?,?)

Here I want to get "table"

I have a pattern but it's working only if there is no brackets like



NB : it's not the same pattern than in get table name from query

Answer Source

This will never be a very fool proof way of extracting table names from SQL. But here is a solution to the problem using regex like you need. You've specified the WHERE part in the provided expression but is it really necessary if you just need the name?


Note that there are many ways a SQL statement can be formatted and it's very unlikely that anyone can come up with an expression that can parse SQL in the way you need.