Regex to strip phpdoc multiline comment

Posted by Reveller on Stack Overflow See other posts from Stack Overflow or by Reveller
Published on 2010-05-01T10:52:40Z Indexed on 2010/05/01 10:57 UTC
Read the original article Hit count: 359

Filed under:
|
|
|

I have this:

/**
 * @file
 * API for loading and interacting with modules.
 * More explaination here.
 *
 * @author  Reveller <me@localhost>
 * @version 19:05 28-12-2008
 */

I'm looking for a regex to strip all but the @token data, so the result would be:

@file API for loading and interacting with modules. More explaination here.
@author Reveller <me@localhost>
@version 19:05 28-12-2008

I now have this:

$text = preg_replace('/\r?\n *\* */', ' ', $text);

It does the job partially: it only removes the * in front of each line. Who could help me so it also strips /** and the final slash /? Any help would be greatly appreciated!

P.S: If, for instance, the commentlbock would contain something like

/**
 * @foo Here's some slashes for ya: / and \
 */

Then obviously the slashes after @foo may not be stripped. The reult would have to be:

@foo Here's some slashes for ya: / and \

I hope there's a regex guru out there :-)

© Stack Overflow or respective owner

Related posts about phpdoc

Related posts about regex