1

I'm looking for a regex string to parse a property type from it's comment as below.

/**
 * Identity
 * 
 * @var integer
 */
protected $id;

I'm using the ReflectionProperty class to get the comment as a string as the var dump below:

string(55) "/** * Identity * * @var integer */"

How would use the regex to return the type after @var and nothing else.

Thanks

4

1 回答 1

2

The proposed solution in the comments seems rather excessive... should be much easier like this - as types never contain spaces, just match until the space.

/@var\s*([^\s]+)/i

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

于 2015-07-27T10:45:37.627 回答