如何使用 PHP/Regex 解析 Google Voice 电子邮件地址


How do i parse a Google Voice email address with PHP/Regex?

我想使用 PHP 从以下字符串中提取16197226146

"(480) 710-6186" <18583894531.16197226146.S7KH51hwhM@txt.voice.google.com>

有人可以帮我处理正则表达式吗?

<'d*?'.('d+)

<    Match "<"
'd   Match digits
   *    0 or more times
   ?    Lazy, take as little as possible
'.   Match a "."
(    Capture
   'd   Match digits
   +    1 or more times
)    Stop capturing

这与.后的第二个数字匹配。比赛在第 1 组中。

if (preg_match("/<'d*?'.('d+)/", $subject, $regs)) {
    $result = $regs[1];
} else {
    $result = "";
}

您可以在此处使用正则表达式。

你可以使用爆炸。

$value = "(480) 710-6186"<18583894531.16197226146.S7KH51hwhM@txt.voice.google.com>";
$result  = explode('.', $value);
echo $result[1]; // is 16197226146