I am not that hot at regular expressions and it has made my little mind melt some what.
I am trying to find all the tables names in a query. So say I have the query
In PHP, I use this function, it returns an array with the table names used in a sql statement:
function sql_query_get_tables($statement){
preg_match_all("/(from|into|update|join) [\\'\\´]?([a-zA-Z0-9_-]+)[\\'\\´]?/i",
$statement, $matches);
if(!empty($matches)){
return array_unique($matches[2]);
}else return array();
}
Notice that it does not work with a,b joins or schema.tablename naming
I hope it works for you