|
Posted by Fluffy Convict on 06/09/05 23:38
In my school's website, I've found a regex that scans files for
functions which name's end with "_ding". On a match, it scans the
JavaDoc style comment of the function and filers out any @user comments.
Perhaps the following example will explain this better:
---------------------------- PHP: -----------------------------
preg_match_all(
";
/\*\* #Comment start
(?P<Comment>.*?) #Comment contents
\*/ #End of the comment
\s*
function\s+(?P<Function>[a-z0-9_]*_ding) #Function name
;xim",
$file,
$matches,
PREG_SET_ORDER
);
---------------------------------------------------------------
Let's assume $file is scanned with this regex and $file contains the
following function:
/**
* @description This is for internal use
* @user This is to inform the user
*/
function foo_ding() {
return 'foo!';
}
Then the output of the rexex would be "This is to inform the user". Now
my problem. It's really quite simple I imagine for somebody with more
regex experience than I have. I now want to match functions that START
with ding_ and not end with it. So the regex should match
/**
* @user Inform the user
*/
function ding_foo() {
return 'foo you too!'
}
Who knows how to rebuild the regex? I've tried the code here under, but
It failt to return the whole function name. $matches['Function'] returns
"ding_f" instead of "ding_foo". Who can help me rewrite this regex
properly? Your help would be greatly appreciated!
---------------------------- PHP: -----------------------------
preg_match_all(
";
/\*\* #Comment start
(?P<Comment>.*?) #Comment contents
\*/ #End of the comment
\s*
function\s+(?P<Function>ding_*[a-z0-9_]) #Function name
;xim",
$file,
$matches,
PREG_SET_ORDER
);
---------------------------------------------------------------
Navigation:
[Reply to this message]
|