Re: Regex guru needed

From: Date: Sat, 13 Nov 2004 17:03:26 +0000
Subject: Re: Regex guru needed
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-34376@lists.php.net to get a copy of this message
Hi bertrand Gugger! On 11/13/2004 10:57 AM you wrote:
Tobias Schlitt wrote:
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)?
Hello Tobias, You have it in PHP doc: When a capturing subpattern is repeated, the value captured is the substring that matched the final iteration. For example, after (tweedle[dume]{3}\s*)+ has matched "tweedledum tweedledee" the value of the captured substring is "tweedledee". So your result is normal. I think you must catch the whole between the parenthesis, and then split it with spaces as: $string = "(aaa bbb ccc ddd)"; $regex = "/\(((?:(?:[a-z]+)\s*)+)\)/"; preg_match($regex, $string, $matches); $param= preg_split('/\s+/', $matches[1]); var_dump($param);
That's especially what I wanted to avoid, since having all in 1 regex is much faster than spliting every result again. -- 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

« previous php.pear.dev (#34376) next »