YouTube URL matcher, video ID catcher


/ Published in: Regular Expression
Save to your folder(s)

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 (youtu.be). It also supports international URLs.

Tested with Javascript and PHP.


Copy this code and paste it in your HTML
  1. /http:\/\/(?:youtu\.be\/|(?:[a-z]{2,3}\.)?youtube\.com\/watch(?:\?|#\!)v=)([\w-]{11}).*/gi

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.