Skip to content

Instantly share code, notes, and snippets.

@selimb86
Last active December 12, 2015 09:19
Show Gist options
  • Save selimb86/4751026 to your computer and use it in GitHub Desktop.
Save selimb86/4751026 to your computer and use it in GitHub Desktop.
This snippets show how to extract the video id of a youtube video from its URL
// Source : http://stackoverflow.com/questions/3452546/javascript-regex-how-to-get-youtube-video-id-from-url
var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/;
var match = url.match(regExp);
if (match&&match[2].length==11){
return match[2];
}else{
//error
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment