我正在编写一个php脚本,我需要创建一个正则表达式规则来匹配两种类型的字符串(下面代码中的string1和string2),匹配的数字需要在$ matches [1]中(不应该匹配) [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\n";
echo "TN2: $ticketNumber2";
echo "\n";
?>
任何人都能帮助我吗?应该用什么正则表达式得到结果?
请帮助。