Hi,
I tried this code:
<?PHP
$sql = "select user_id as id, concat_ws(' ',user_name, user_lastname) as name, s.name as state, (6+4) as operation from user as u, state as s";
$match = preg_match_all("/(?<!from)[,\\s]([^,]*?|\\w*?\\(.*?\\)) as ([^,]*?)[,\\s]/i",$sql,$matches);
print_r($matches);
?>
Matches is the following array:
Array
(
[0] => Array
(
[0] => user_id as id,
[1] => concat_ws(' ',user_name, user_lastname) as name,
[2] => s.name as state,
[3] => (6+4) as operation
)
[1] => Array
(
[0] => user_id
[1] => concat_ws(' ',user_name, user_lastname)
[2] => s.name
[3] => (6+4)
)
[2] => Array
(
[0] => id
[1] => name
[2] => state
[3] => operation
)
)
matches[1] and matches[2] contain the important data.
matches[1][n] and matches[2][n] are the corresponding values where matches[1] contains the field/calc and matches[2] contains the alias.
Thomas