正则表达式:如何在"@"符号之前删除电子邮件?

st4*_*l0w 8 php regex string

我有以下字符串

First Last <first.last@email.com>
Run Code Online (Sandbox Code Playgroud)

我想提取

"first.last" 
Run Code Online (Sandbox Code Playgroud)

从使用正则表达式和PHP的电子邮件字符串.怎么去这个?

提前致谢!

gho*_*g74 6

$str ="First Last <first.last@email.com>";
$s = explode("@",$str);
$t = explode("<",$s[0]);
print end($t);
Run Code Online (Sandbox Code Playgroud)


Eri*_*rik 6

我知道答案已被接受,但这将适用于以下格式的任何有效电子邮件地址: Name <identifier@domain>

// Yes this is a valid email address
$email = 'joey <"joe@work"@example.com>';

echo substr($email, strpos($email,"<")+1, strrpos($email, "@")-strpos($email,"<")-1);
// prints: "joe@work"
Run Code Online (Sandbox Code Playgroud)

大多数其他发布的解决方案将在许多有效的电子邮件地址上失败.