Webflags: g

YouTube Video ID

Extract 11-character YouTube video IDs from long URLs, short URLs, or embed URLs.

Try it in RegexPro

Pattern

regexJavaScript
/(?:youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/)([\w\-]{11})/g

Raw source: (?:youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/)([\w\-]{11})

How it works

Matches any of three URL forms (watch?v=, youtu.be/, embed/) and captures the 11-character video ID that follows. The ID uses word characters and hyphens.

Examples

Input

https://www.youtube.com/watch?v=dQw4w9WgXcQ

Matches

  • youtube.com/watch?v=dQw4w9WgXcQ

Input

https://youtu.be/dQw4w9WgXcQ

Matches

  • youtu.be/dQw4w9WgXcQ

Input

not a youtube url

No match

Common use cases

  • Content scraping and normalisation
  • Embed URL rewriting
  • Analytics tagging and attribution
  • Link preview rendering