krebernisak
10/28/2013 - 10:50 AM

From http://stackoverflow.com/questions/3452546/javascript-regex-how-to-get-youtube-video-id-from-url

function youtube_parser(url) {
    var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
    var match = url.match(regExp);
    if (match && match[7].length === 11) {
        return match[7];
    } else {
        alert("Url incorrecta");
    }
}