Regex YouTube channel link

I’m looking for a Javascript regex which is able to extract the channel identifier of a YouTube channel link. I’ve found some solutions on Stackoverflow but I’m still missing a solution which is also capable to work with the YouTube channel alias (e.g.

So the regex should be able to match following URLs:

  1. –> coca-cola
  2. –> UCosXctaTYxN4YPIvI5Fpcrw
  3. –> coca-cola
  4. –> coca-cola

The matching should also work even when there’s a path attached like

Any hints are welomce!

>Solution :

The pattern you’re looking for is:

const urls = [

const pattern = /https:\/\/www\.youtube\.com\/(?:c\/|channel\/|@)?([^/]+)(?:\/.*)?/

for (url of urls) {

Leave a Reply