1

I would like to extract 16197226146 from the following string using PHP:

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

Could someone please help me with the regex please?

Josiah
  • 1,117
  • 5
  • 22
  • 35

2 Answers2

4

<\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

That matches the second number after a .. The match is in group 1.

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

You can play with the regex here.

David B
  • 2,688
  • 18
  • 25
0

You could use explode.

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

$result  = explode('.', $value);
echo $result[1]; // is 16197226146
Papa De Beau
  • 3,744
  • 18
  • 79
  • 137