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 Pattern | Name / Component | Function & Rule |
|---|---|---|
| youtu\.be\/|youtube\.com... | URL Domain Prefix | Matches all standard YouTube domain variants. |
| ([\w-]{11}) | Video ID Group | Captures exact 11 alphanumeric and dash characters. |
Frequently Asked Questions
Does this support YouTube Shorts?
Related Regular Expressions
Browse All 40 PatternsNetwork & Web
HTTP & HTTPS URL Validation
Matches fully qualified URLs starting with http:// or https://, including subdomains, paths, ports, and query parameters.
/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}(?:\.[a-zA-Z0-9()]{1,6})?(?::[0-9]{1,5})?\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/iTest regex
Network & Web
Domain Name Matcher
Validates Fully Qualified Domain Names (FQDN) adhering to DNS hostname specification (RFC 1035).
/^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/Test regex
Code & Markup
Markdown Links Parser
Captures anchor text and target URL from Markdown link syntax `[text](url)`.
/\[([^\]]+)\]\((https?:\/\/[^\s\)]+)\)/gTest regex