Over a million developers have joined DZone.

Extract Youtube Video ID from URL

DZone's Guide to

Extract Youtube Video ID from URL

· ·
Free Resource

 This snippets show how to extract the video id of a youtube video from its URL

    /* Source : http://stackoverflow.com/questions/3452546/javascript-regex-how-to-get-youtube-video-id-from-url  */
    var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/;
    var match = url.match(regExp);
    if (match&&match[2].length==11){
        return match[2];

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}