PHP正则表达式和DocComment值解析

I am trying to parse the value a doc block comment

$str = "/**
 * @title View/List Permissions
 * @description Allow user to view list of permissions
 */";

The code that I am using is shown below:

$re = "/^.*@title\s+(\S*).*@description\s+(\S*).*$/s"; 
preg_match($re, $str, $matches);

The current result is as follows:

[0] View/List
[1] Allow

https://regex101.com/r/dA7jW2/2

What can I do to get the the fill "View/List Permissions" and "Allow user to view list of permissions"?

I have tried to modify the regex by replacing the \s+(\S*).* with \s+(\S.*) and while it works to some extent, it is adding the * from the next line

https://regex101.com/r/dA7jW2/3

Any ideas will help..

Thanks

I changed \S to [^ ] and matched the rest of the string to the end of the line.

^.*@title\s+([^
]*).*@description\s+([^
]*).*$

Outputs:

MATCH 1
1.  [14-35] `View/List Permissions`
2.  [52-90] `Allow user to view list of permissions`

https://regex101.com/r/dA7jW2/4

That [^] is a negative character class, so you can list all the characters you don't want to match. [^ ] says match character that's not a new line.

Try

/^.*@title\s+(.*)\s*\*\s*@description\s+(.*).*$/s

The problems you are having are:

1) When you do (\S*) it stops after the first whitespace character you get to (in this case, a space), so you need to do (.*)

2) You need to handle any number of spacing after "Permissions" (spaces or return characters), followed by a *, followed by any additional whitespace before "@description"

Hope that helps