用于从Rumble URL中提取视频ID的正则表达式

Argh-- regular expressions make me crazy, I've just spent 20 minutes trying to get this to fly and I'm having no luck. And I know someone here will be able to pop this out in like 2 seconds! :-)

Here's a sample source URL: https://rumble.com/v30sqt-oreo-ice-cream-cake.html

I want to extract the "v30sqt" characters. Actually, I want to extract any characters after "rumble.com/" and before the first dash. It might be alphanumeric, it might be all letters, it might be longer than 6 characters, etc. That's the video ID.

This is for php preg_match.

Try this one should work for you :

/(?<=rumble.com\/).*?\b/g

Demo and Explaination

You can simply use parse_url instead of using regex along with explode and current function like as

$url = "https://rumble.com/v30sqt-oreo-ice-cream-cake.html";
$parsed_arr = explode("-",ltrim(parse_url($url, PHP_URL_PATH),"/"));
echo current($parsed_arr);

or

echo $parsed_arr[0];

Demo

Go for:

<?php

$url = "https://rumble.com/v30sqt-oreo-ice-cream-cake.html";
$regex = '~rumble\.com/(?P<video>[^-]+)~';

if (preg_match($regex, $url, $match)) {
    echo $match['video'];
    # v30sqt
}
?>

With a demo on ideone.com.