<?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])); }
You have javascript disabled. You will not be able to edit any code.