HomeRegex LibraryYouTube Video ID & URL Extractor Regex
100% Client-Side β€’ 0 B Data Leaves Browser
web

YouTube Video ID & URL Extractor Regex

Matches YouTube video URLs and captures the 11-character unique video identifier.

Regular Expression Pattern:
/^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))([\w-]{11})(?:\S+)?$/i
Valid Match Example:
https://www.youtube.com/watch?v=dQw4w9WgXcQ
Invalid / Non-Match Example:
https://vimeo.com/123456

Regex Syntax Breakdown & Explanation

  • β€’Captures the 11-character alphanumeric YouTube ID from youtu.be, embed, or watch URLs.

Implementation in Popular Languages

JavaScript / TypeScript
const regex = /^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))([\w-]{11})(?:\S+)?$/i;
const isValid = regex.test("https://www.youtube.com/watch?v=dQw4w9WgXcQ");
console.log(isValid); // true
Python (re)
import re

pattern = r"^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))([\w-]{11})(?:\S+)?$"
match = re.match(pattern, "https://www.youtube.com/watch?v=dQw4w9WgXcQ")
print(bool(match)) # True
Go (regexp)
package main
import (
  "fmt"
  "regexp"
)

func main() {
  re := regexp.MustCompile(`^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))([\w-]{11})(?:\S+)?$`)
  fmt.Println(re.MatchString("https://www.youtube.com/watch?v=dQw4w9WgXcQ"))
}
Frequently Asked Questions

Frequently Asked Questions

Everything you need to know regarding specifications, syntax, and security best practices.

The regular expression pattern is /^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))([\w-]{11})(?:\S+)?$/i. Matches YouTube video URLs and captures the 11-character unique video identifier.