I have the following code which detect the video id from a string. It actually catch more cases that I need, and I would like to make it more simply and return the id only for string in this formats:
https://www.youtube.com/watch?v=85PMSYAguZ8
https://youtu.be/85PMSYAguZ8
Code:
_getVideoIdFromUrl: function (value) {
var regEx = /^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/;
var matches = value.match(regEx);
if (matches) {
return matches[1];
}
return false;
},
I would need help to change the regEx accordingly, any ideas?
Currently it detects:
YES 'http://www.youtube.com/watch?v=cKZDdG9FTKY&feature=channel',
YES 'http://www.youtube.com/watch?v=yZ-K7nCVnBI&playnext_from=TL&videos=osPknwzXEas&feature=sub',
YES 'http://youtu.be/6dwqZw0j_jY',
YES 'http://www.youtube.com/watch?v=6dwqZw0j_jY&feature=youtu.be',
YES 'http://www.youtube.com/watch?v=yZ-K7nCVnBI&playnext_from=TL&videos=osPknwzXEas&feature=sub',
YES 'http://www.youtube.com/embed/nas1rJpm7wY?rel=0',
YES 'http://www.youtube.com/watch?v=peFZbP64dsU',
YES 'http://youtube.com/v/dQw4w9WgXcQ?feature=youtube_gdata_player',
YES 'http://youtube.com/watch?v=dQw4w9WgXcQ&feature=youtube_gdata_player',
YES 'http://www.youtube.com/watch?v=dQw4w9WgXcQ&feature=youtube_gdata_player',
YES 'http://youtu.be/afa-5HQHiAs',
YES 'http://youtu.be/dQw4w9WgXcQ?feature=youtube_gdata_player'
NO '//www.youtube-nocookie.com/embed/up_lNV-yoK4?rel=0',
NO 'http://www.youtube.com/user/Scobleizer#p/u/1/1p3vcRhsYGo',
NO 'http://www.youtube.com/ytscreeningroom?v=NRHVzbJVx8I',
NO 'http://www.youtube.com/user/SilkRoadTheatre#p/a/u/2/6dwqZw0j_jY',
NO 'http://www.youtube.com/user/Scobleizer#p/u/1/1p3vcRhsYGo?rel=0',
NO 'http://www.youtube.com/watch?v=cKZDdG9FTKY&feature=channel',
NO 'http://www.youtube.com/ytscreeningroom?v=NRHVzbJVx8I',
NO 'http://youtube.com/vi/dQw4w9WgXcQ?feature=youtube_gdata_player',
NO 'http://youtube.com/?v=dQw4w9WgXcQ&feature=youtube_gdata_player',
NO 'http://youtube.com/?vi=dQw4w9WgXcQ&feature=youtube_gdata_player',
NO 'http://youtube.com/watch?vi=dQw4w9WgXcQ&feature=youtube_gdata_player',