DEV Community 👩‍💻👨‍💻

Matt Kenefick
Matt Kenefick

Posted on

Regex: Extract YouTube ID from URL

if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/\s]{11})%i', $url, $match)) {
    return $match[1];
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Dream Big


Use any Linode offering to create something unique or silly in the DEV x Linode Hackathon 2022 and win the Wacky Wildcard category.

Join the Hackathon <-