I’m trying to parse custom annotations out of a document block retrieved via ReflectionClass::getDocComment. I figured using preg_match_all with the regex "/(@\w+)\s+([^@]+)/" with the PREG_SET_ORDER flag would do what I want. I tested it in an interactive shell and it seemed golden.
What I didn’t think to test was the @author tag from phpdoc. The optional email address for the author tag (obviously) has an @ in it. I can’t use \b inside the character class of the regex to require the @ be at the start of a word because it won’t be interpreted as a word boundary character but a backspace.
I need some inspiration!
Update:
Thank you Arne, your answer gave me some ideas but I prefer a general solution to one that adapts only to the specific issue at hand.
I’ve come up with two possibilities so far. The first one only works if there is a trailing space which there currently is but I’m not sure that I can guarantee there always will be. The second one appears to work regardless but is much less … finessful.
First regex is "/(@\w+)\s+((?:[^@]\S*?\s+)*)/"
Second regex is "/(@\w+)\s+((?:[^@]\S*?(?:\s|$)+)*)/"
Perhaps someone can help me clean up the second one.
\b as word boundary can’t be used inside a character class, because \b as word boundary is a pattern, not a character.
I guess you want to match something like
and your interested in the annotations name and parameter.
If you simply extend your character family to not contain the
<and append an optional pattern for the mail address, you may end up with something like this:I don’t know if this matches all annotations of your interest, but may be it’s a starting point.