Re: Regex help please

From: Date: Mon, 12 Jan 2004 00:21:06 +0000
Subject: Re: Regex help please
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-174268@lists.php.net to get a copy of this message
Try this: $pattern = '#function (\w+)\(((?:\$\w+(?:,\s*\$\w+)*?)|\s*)\)\s*\{[.\s]*((?:return\s+[^;]*\s*;)|)[ .\s]*#m'; Notice that \w means: A "word" character is any letter or digit or the underscore character, that is, any character which can be part of a Perl "word". Though, any regexp for this task can be easily fooled; i.e: there's no regexp for all cases; PHP's language cannot be described properly using just a regular expression. Manu. "Shawn McKenzie" <nospam@mckenzies.net> wrote in message news:20040111234828.8236.qmail@pb1.pair.com... > I have tried numerous variations, but my regex skills suck! I would > appreciate anyone who can give me a pattern to use in preg_match_all() to > match the following (I have the first part up to ANYTHING working): > > '|function ([\w\d\_]+)\((.*)\)ANYTHINGreturn (ANYTHING);|' > > So parsing a PHP file I hope to have 3 backreferences that return the > "function name", "function args" and "return value (if present)" > of all > functions. > > Thanks! > -Shawn >

« previous php.general (#174268) next »