Social
YouTube channel URL Regex
A YouTube channel can be linked in three common ways: the modern @handle form, the permanent channel ID that starts with UC and has 22 more characters, and the older /c/ custom URL. This pattern accepts all three, with optional https and www and an optional trailing slash. Use it in creator directories, sponsorship forms and social profile fields where people paste whatever link they have. It deliberately rejects video and playlist URLs so they are not mistaken for channels. It does not cover the old /user/ format, and a match does not mean the channel still exists.
Pattern (JavaScript)
/^(?:https?://)?(?:www\.)?youtube\.com/(?:@[A-Za-z0-9._-]{3,30}|channel/UC[A-Za-z0-9_-]{22}|c/[A-Za-z0-9_-]+)/?$/Starts at the start of the line/string, then (the text "http", then the character "s", optionally (zero or one time), then the text "://"), optionally (zero or one time), then (the text "www."), optionally (zero or one time), then the text "youtube.com/", then (the character "@", then one of the characters A-Za-z0-9._-, between 3 and 30 times OR the text "channel/UC", then one of the characters A-Za-z0-9_-, exactly 22 times OR the text "c/", then one of the characters A-Za-z0-9_-, one or more times), then the character "/", optionally (zero or one time), then the end of the line/string.
Examples
Matches
- ✓ https://www.youtube.com/@test_channel
- ✓ youtube.com/channel/UC1234567890abcdefghijkl
- ✓ https://youtube.com/c/TestChannel/
Does not match
- ✗ https://www.youtube.com/watch?v=AbCdEfGhIjK
- ✗ https://www.youtube.com/@ab
- ✗ https://example.com/@test_channel
- ✗ https://www.youtube.com/channel/UC123
Try it
0 matches (JavaScript engine)
https://www.youtube.com/@test_channel
youtube.com/channel/UC1234567890abcdefghijkl
https://youtube.com/c/TestChannel/
https://www.youtube.com/watch?v=AbCdEfGhIjK
https://www.youtube.com/@ab
https://example.com/@test_channel
https://www.youtube.com/channel/UC123Code in 8 languages
Converted automatically from the JavaScript pattern; language-specific notes are shown where the syntax or support differs.
JavaScript
const re = /^(?:https?:\/\/)?(?:www\.)?youtube\.com\/(?:@[A-Za-z0-9._-]{3,30}|channel\/UC[A-Za-z0-9_-]{22}|c\/[A-Za-z0-9_-]+)\/?$/g;
const text = "https://www.youtube.com/@test_channel";
const matches = [...text.matchAll(re)].map((m) => m[0]);
console.log(matches);Python
import re
pattern = re.compile(r'^(?:https?://)?(?:www\.)?youtube\.com/(?:@[A-Za-z0-9._-]{3,30}|channel/UC[A-Za-z0-9_-]{22}|c/[A-Za-z0-9_-]+)/?$')
text = 'https://www.youtube.com/@test_channel'
matches = [m.group(0) for m in pattern.finditer(text)]
print(matches)PHP
<?php
$pattern = '#^(?:https?://)?(?:www\.)?youtube\.com/(?:@[A-Za-z0-9._-]{3,30}|channel/UC[A-Za-z0-9_-]{22}|c/[A-Za-z0-9_-]+)/?$#';
$text = 'https://www.youtube.com/@test_channel';
preg_match_all($pattern, $text, $matches);
print_r($matches[0]);Java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("^(?:https?://)?(?:www\\.)?youtube\\.com/(?:@[A-Za-z0-9._-]{3,30}|channel/UC[A-Za-z0-9_-]{22}|c/[A-Za-z0-9_-]+)/?$");
String text = "https://www.youtube.com/@test_channel";
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}Go
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^(?:https?://)?(?:www\.)?youtube\.com/(?:@[A-Za-z0-9._-]{3,30}|channel/UC[A-Za-z0-9_-]{22}|c/[A-Za-z0-9_-]+)/?$`)
text := "https://www.youtube.com/@test_channel"
fmt.Println(re.FindAllString(text, -1))
}C#
using System;
using System.Text.RegularExpressions;
var pattern = new Regex(@"^(?:https?://)?(?:www\.)?youtube\.com/(?:@[A-Za-z0-9._-]{3,30}|channel/UC[A-Za-z0-9_-]{22}|c/[A-Za-z0-9_-]+)/?$");
var text = "https://www.youtube.com/@test_channel";
foreach (Match m in pattern.Matches(text))
{
Console.WriteLine(m.Value);
}Rust
// Cargo.toml: regex = "1"
use regex::Regex;
fn main() {
let re = Regex::new(r"^(?:https?://)?(?:www\.)?youtube\.com/(?:@[A-Za-z0-9._-]{3,30}|channel/UC[A-Za-z0-9_-]{22}|c/[A-Za-z0-9_-]+)/?$").unwrap();
let text = "https://www.youtube.com/@test_channel";
for m in re.find_iter(text) {
println!("{}", m.as_str());
}
}- Add regex = "1" under [dependencies] in Cargo.toml.
Ruby
pattern = /^(?:https?:\/\/)?(?:www\.)?youtube\.com\/(?:@[A-Za-z0-9._-]{3,30}|channel\/UC[A-Za-z0-9_-]{22}|c\/[A-Za-z0-9_-]+)\/?$/
text = 'https://www.youtube.com/@test_channel'
matches = text.to_enum(:scan, pattern).map { Regexp.last_match[0] }
p matchesFrequently asked questions
- Which channel URL form should I store?
- Store the channel ID form when you can, because handles and custom URLs can change while the UC identifier is permanent. Accept all three on input and resolve them to the ID through the YouTube API if needed.
- Why must channel IDs start with UC?
- YouTube channel IDs are 24 characters and begin with UC by convention. Requiring the prefix and the exact length filters out playlist IDs and other similar-looking strings.
- Does this accept youtube.com/user/ links?
- No. The /user/ form is a legacy format that YouTube no longer creates. Add another alternative such as user/[A-Za-z0-9]+ if your data still contains those links.
Related patterns
- YouTube video URL^(?:https?://)?(?:www\.|m\.)?(?:youtube\.com/(?:watch\?v=|shorts/|embed/)|youtu\.be/)[A-Za-z0-9_-]{11}(?:[?&#]\S*)?$
- Discord invite link^(?:https?://)?(?:www\.)?(?:discord\.gg|discord(?:app)?\.com/invite)/[A-Za-z0-9-]{2,32}/?$
- Facebook page URL^(?:https?://)?(?:www\.|m\.)?(?:facebook|fb)\.com/[A-Za-z0-9.]{5,50}/?$
- GitHub repository URL^(?:https?://)?(?:www\.)?github\.com/[A-Za-z0-9](?:-?[A-Za-z0-9]){0,38}/[A-Za-z0-9._-]+?(?:\.git)?/?$