Re: Regex guru needed
| From: | bertrand Gugger | Date: | Sat, 13 Nov 2004 15:57:19 +0000 |
| Subject: | Re: Regex guru needed | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-34373@lists.php.net to get a copy of this message | ||
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); Bye bertrand Gugger (toggg)