PHP正则表达式用于匹配两个句子中的数字

I'm writing a php script where I need to create a regex rule to match two types of strings ( string1 and string2 in below code) and the matched number needs to be in $matches[1] ( should not be matches[2] ).

<?php
$ticketNumber1 = $ticketNumber2 = '';
$string1 = "[Ticket ID: 309972] New Support Ticket Opened";
$string2 = "Ticket #: 656398";
$regex = "/Ticket #|ID: (\d+)/";
if(preg_match($regex, $string1, $matches))
{
        $ticketNumber1 = $matches[1];
}
if(preg_match($regex, $string2, $matches))
{
        $ticketNumber2 = $matches[1];
}
echo "TN1: $ticketNumber1
";
echo "TN2: $ticketNumber2";
echo "
";
?>

Can any one help me with this? What should be the regex to be used to get the result?

Kindly help.

You need to limit the scope of the operator OR by using a non-capturing group:

/Ticket (?:#|ID): (\d+)/

regex101 demo