$re = '/^\s*(?P<modifiers>(?:\s*(?:private|const|static))*)\s*(?P<fulltype>(?P<type>[^\s<\[{]+)\s*(?P<generics><\s*.+\s*>)?)\s+(?P<name>[^\s<{]+)\s*(?:=\s*(?P<value>.+))?$/m';
$str = ' MyClass name
private MyClass name
MyClass < T , U > name
MyClass < T < U > > name
private static MyClass < T > name
private static MyClass < T < U > > name
InputDeviceCharacteristics handCharL = InputDeviceCharacteristics.Controller | InputDeviceCharacteristics.Left
const float ResizeSpeed = 0.5f';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php