-1

I need to get the id of a youtube content, so far I can achieve it for a URL like this:

var obtenerUrlId = function(url){
    var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
    var match = url.match(regExp);
    return (match&&match[7].length==11)? match[7] : false;
}
Asher
  • 101
  • 1
  • 1
    Possible duplicate of [How do I get the YouTube video ID from a URL?](https://stackoverflow.com/questions/3452546/how-do-i-get-the-youtube-video-id-from-a-url) – Alon Eitan Apr 09 '19 at 17:49

1 Answers1

0

You can use this snipped to get youtubeId from a url

var splited = recipes.video.split('/');
var lastPart = splited[splited.length - 1];
var id = lastPart.split('watch?v=');
var youtubeId = id[id.length - 1];
Ertan Hasani
  • 1,675
  • 12
  • 27