Posted By

nkm on 04/27/10


url javascript php video regexp match uri id YouTube

Versions (?)

Who likes this?

2 people have marked this snippet as a favorite


YouTube URL matcher, video ID catcher

 / Published in: Regular Expression

PCRE that matches any kind of YouTube URL and catches its video ID. It supports three kinds of URL: the classic (?v=), the AJAXed one (#!v=) and the short version ( It also supports international URLs.

Tested with Javascript and PHP.

  1. /http:\/\/(?:youtu\.be\/|(?:[a-z]{2,3}\.)?youtube\.com\/watch(?:\?|#\!)v=)([\w-]{11}).*/gi

Report this snippet  


RSS Icon Subscribe to comments
Posted By: ofadlaoui on July 29, 2010

Thanks for uploading this

Posted By: fris on December 29, 2010

how about matching /v/id urls as well.

You need to login to post a comment.