Skip to main content
Network & Web · In-Browser Regular Expression Lab

YouTube Video ID Regex — Extract 11-Char ID from Any YouTube URL

Extracts the unique 11-character video ID from watch?v=, youtu.be, shorts/, and embed/ links.

Flags:
//none
Match Found
Load Sample:
Match Inspection & Details1 match
Match #1:youtube.com/watch?v=dQw4w9WgXcQ

Test Samples Verification Matrix

Expected Valid Samples (Should Match)

https://www.youtube.com/watch?v=dQw4w9WgXcQ Pass
https://youtu.be/dQw4w9WgXcQ Pass
https://youtube.com/shorts/dQw4w9WgXcQ Pass

Expected Invalid Samples (Must Reject)

https://youtube.com Rejected (Pass)
https://youtube.com/feed/trending Rejected (Pass)
Code Implementation Generator
// JavaScript / TypeScript (ES6+)
const pattern = /(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|shorts\/|watch\?v=|watch\?.+&v=))([\w-]{11})/;
const text = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";

const isMatch = pattern.test(text);
console.log("Is Match:", isMatch);

if (isMatch) {
  const matches = text.match(pattern);
  console.log("Matches:", matches);
}

Regular Expression Token Breakdown

Captures the standard 11-character base64-like alphanumeric video identifier. Each component of the regular expression serves a distinct syntactical purpose as mapped below:

Token PatternName / ComponentFunction & Rule
youtu\.be\/|youtube\.com...URL Domain PrefixMatches all standard YouTube domain variants.
([\w-]{11})Video ID GroupCaptures exact 11 alphanumeric and dash characters.

Frequently Asked Questions

Does this support YouTube Shorts?
Yes, `shorts/` path is explicitly included in the prefix group.
Browse All 40 Patterns