Regex guru needed
| From: | Tobias Schlitt | Date: | Sat, 13 Nov 2004 14:44:52 +0000 |
| Subject: | Regex guru needed | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-34370@lists.php.net to get a copy of this message | ||
Hi all!
I try creating a regex which extracts all function/method prototypes from a PHP file. So far, I went pretty well, besides one problem. The regex below works pretty well, but only the last parameter of a function declaration is extracted. Maybe someone can give me a hint how to get all parameters (into seperate array elements)?
To show you, what I mean I wrote a little example which shows the same bahavior with much fewer code:
<snip title="code">
$string = "(aaa bbb ccc ddd)";
$regex = "/\((?:
([a-z]+)\s*
)+\)/x";
preg_match($regex, $string, $matches);
var_dump($matches);
</snip>
<snip title="result">
array(2) {
[0]=>
string(17) "(aaa bbb ccc ddd)"
[1]=>
string(3) "ddd"
}
</snip>
Any ideas?
Regards,
Toby
--
Tobias Schlitt GPG Key: 0xA6529579
a passion for php http://www.schlitt.info
Like to say "thank you"? - http://pear.php.net/wishlist.php/toby