3v4l.org

run code in 500+ PHP versions simultaneously
<?php $pattern = "~(?|^(\w+)|\G(?!^)\h+(\w+))(?:\h+<([^<>\r\n]+)>$)?~"; $strings = [ "Some User Name ", "Some User Name <user.mail@address>" ]; foreach ($strings as $str) { preg_match_all($pattern, $str, $matches); print_r($matches[1]); print_r(array_filter($matches[2])); }

preferences:
21.88 ms | 476 KiB | 4 Q