/ 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 (youtu.be). It also supports international URLs.
Tested with Javascript and PHP.
Tested with Javascript and PHP.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/http:\/\/(?:youtu\.be\/|(?:[a-z]{2,3}\.)?youtube\.com\/watch(?:\?|#\!)v=)([\w-]{11}).*/gi