Fixed php line preg_replace
When replacing, you should require something inside the quotation marks.
$str = '"foo" <bar@baz.com>';
preg_replace('/"([^"]+)"\s(<.*?>)/', '$1', $str);
preg_replace('/""\s(<.*?>)/', '$1', $str);
Give it a try. He must leave the address alone if no name is given in front of him.
Edit: Based on your new example inputs and outputs, try the following:
$str = '"foo" <bar@baz.com>';
preg_replace('/"([^"]+)"\s(<.*?>)/', '$1', $str);
preg_replace('/(?:""\s)?(<.*?>)/', '$1', $str);
It should have the following I / O results:
"foo" <bar@baz.com> -> foo
"" <bar@baz.com> -> <bar@baz.com>
<bar@baz.com> -> <bar@baz.com>