Skip to content

Instantly share code, notes, and snippets.

@RobertDaleSmith
Created June 20, 2015 07:54
Show Gist options
  • Save RobertDaleSmith/a54d96961aacd980615e to your computer and use it in GitHub Desktop.
Save RobertDaleSmith/a54d96961aacd980615e to your computer and use it in GitHub Desktop.
Get YouTube ID from URL
function getYouTubeID(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{
return "";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment