正则表达式提取链接的一部分(php)

I got some link like:

/3/topic/video1148288/

and I want to take the number after video. I can't replace the link with only numbers because there are more before the actual video's id.

I tried

$embed = preg_match("#\b/video([0-9][0-9][0-9][0-9][0-9][0-9][0-9])/#", $raw);

But it doesn't work.

Any help?

Give this a try:

$raw = "/3/topic/video1148288/";
preg_match("#/video(\d+)/#", $raw, $matches);
$embed = $matches[1];

Working example: http://3v4l.org/oLPMX

One thing to note from looking at your attempt, is that preg_match returns a truthy/falsely value, not the actual matches. Those are found in the third param ($matches in my example).

$raw = "/3/topic/video1148288/";

preg_match("/video(\d+)/", $raw, $results);

print "$results[1]";
preg_match('/(?<=video)\d+/i', $raw, $match);
echo $match[0];