JSFiddle - React, Tailwind, and code Playground

by ponyspy

JavaScript

var url = 'https://www.youtube.com/watch?v=EvhTR34zLxY#action=share'

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