Variables of regex int php


Variables of regex int php

我得到了一些像phs(2.1.2):someinfo这样的字符串,我想接收一个版本(2.1.2)的变量,它具有php的hel和regexp功能。我得到的是:

        if (preg_match('/phs'((.*)'):/', $line))
        {
            echo $line.'<br>';
        }

这是可以的,但现在我想获得regexp的存储变量。我发现我可以把它作为''1,但当我尝试它时,它在浏览器中是白色屏幕,所以它不起作用。是否可以从regexp中获取变量?或者有更好的解决方案?

使用可选参数preg_matcharray &$matches
类似这样的东西-

$line = "phs(2.1.2):someinfo";
if (preg_match('/phs'((.*)'):/', $line, $matches))
{
    $version = $matches[1];
    echo $version.'<br>';
}
//OUTPUT - 2.1.2