JSFiddle - React, Tailwind, and code Playground
by Rahul Sharma
JavaScript
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");
}
}
console.log(
youtube_parser("https://www.youtube.com/watch?v=xuz7qIjEjmQ"));