Regex PHP正则表达式最后一个实例后的所有数字

Regex PHP正则表达式最后一个实例后的所有数字,regex,Regex,嗨,我想得到最后一个php中的-实例之后的所有数字 我的代码现在是这样的 $results = array(); $pattern = '/[^\-]*$/'; $pattern_no_chars ="[!0-9]"; preg_match($pattern, $alias_title, $matches); if(count($matches) <1){ return $results;

嗨,我想得到最后一个php中的-实例之后的所有数字

我的代码现在是这样的

$results = array();       
    $pattern = '/[^\-]*$/';       
    $pattern_no_chars ="[!0-9]";
    preg_match($pattern, $alias_title, $matches);         

    if(count($matches) <1){
        return $results;
    }

    $last_id = end($matches);
    $id_no_char = preg_replace($pattern_no_chars, '', $last_id);   
$results=array();
$pattern='/[^\-]*$/';
$pattern_no_chars=“[!0-9]”;
preg_match($pattern,$alias_title,$matches);

如果(count($matches)您可以使用
explode()

或者像这样的正则表达式:

/-(\d+)$/
你也可以使用

preg_match('~(?<=-)\d+$~',$str,$m);
if (!empty($m)) echo $m[0];

preg\u match(“~”(?如果您选中此在线正则表达式,则替换时不适用于preg\u match(“/[^-]*$/”,$alias\u title,$matches);$id\u no\u char=preg\u replace(“/([^0-9]+)/”,end($matches))/view?alias_title=network-warringtons-optar-versa-hybrid-yj62fkl-102-1593如果传入它将得到102我如何做这个正则表达式才能成为最后一个实例-感谢这么大的帮助,它将在破折号后得到最后一组数字,所以你不必担心,它只会捕获最后一组(在你之前的评论中是1593)。顺便说一句,在使用这个之前不要忘记修剪URL。在php-preg_-match('~(?smae with trim-preg_-match('~)?
preg_match('~(?<=-)\d+$~',$str,$m);
if (!empty($m)) echo $m[0];
(?<=-)  # last character before the match should be a dash
\d+     # 1 or more decimals (aka. the matched part)
$       # end of string
$str = '/view?alias_title=network-warringtons-optare-versa-hybrid-yj62fkl-102-1593';
preg_match('~(?<=-)\d+$~',$str,$m);
if (!empty($m)) echo $m[0];