Back to all patterns
YouTube URL, Extract Video ID
Extraction
Extracts the 11-char video ID from any common YouTube URL shape.
/(?:youtube\.com/(?:watch\?v=|embed/|shorts/|v/)|youtu\.be/)([a-zA-Z0-9_-]{11})/iHow it works
Handles youtube.com/watch?v=, /embed/, /shorts/, /v/, and youtu.be/ short links. Capture group 1 is the video ID.
Test Cases
Should Match
- https://www.youtube.com/watch?v=dQw4w9WgXcQ
- https://youtu.be/dQw4w9WgXcQ?t=42
- https://www.youtube.com/shorts/dQw4w9WgXcQ
Should NOT Match
- https://vimeo.com/12345
- youtube.com/feed/subscriptions
Quick Summary
Extracts a YouTube video ID from watch, embed, shorts, or short-link URLs (group 1).