Say I have the following string: Func(param1, param2)
with an unknown number of params.
And I want to get the following array:
Array(
[0] => Func(param1, param2),
[1] => Func
[2] => param1,
[3] => param2,
...
)
I tried this:
$str = 'Func(param1, param2)';
preg_match('/^([a-z]+)\((?:([a-z0-9]+)\s*,?\s*)*\)$/i', $str, $matches);
print_r($matches);
And that is the output:
Array
(
[0] => Func(param1, param2)
[1] => Func
[2] => param2
)
The sub pattern that captures the params captures only the last param. And I want it to capture all of the parameters.
Any ideas?
EDIT:
I know I can capture all of the params and then use explode. But that is not my question.
I want to know how it is done with regular expressions.