DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Slim has posted 1 posts at DZone. View Full User Profile

Extract Youtube Video ID from URL

02.10.2013
| 895 views |
  • submit to reddit
    /* 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];
    }else{
        //error
    }

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

Comments

Michael Molo replied on Thu, 2013/02/21 - 1:36am