获取PHP字符串中的下一个直接数字子字符串


Get the next immediate numeric substring in a PHP string

我有一些以下字符串:

Total: 14,785 | Daily: 4785
Total: 14,785 |
Total: 14,785 
Total: 14,785

现在我想从整个字符串中获取数字字符串,比如"14,785"

如何通过使用preg_match或其他东西来做到这一点。我使用了以下技巧

function getBetween($content,$start,$end){
    $r = explode($start, $content);
    if (isset($r[1])){
        $r = explode($end, $r[1]);
        return $r[0];
    }
    return '';
}

但是只有当"|"会在那里。我该怎么解决这个问题?

对捕获组使用正则表达式:

preg_match('/^Total: (['d,]+)/', $content, $match);
$number = $match[1];

是这样吗?

https://regexr.com/398nc

正则表达式:

Total: (['d,]*)