Skip to content

Instantly share code, notes, and snippets.

@joemcgill
Created September 16, 2013 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joemcgill/6586169 to your computer and use it in GitHub Desktop.
Save joemcgill/6586169 to your computer and use it in GitHub Desktop.
A handy javascript function for parsing YouTube urls and returning just the video URI (adapted from: http://stackoverflow.com/posts/9102270/revisions).
function parse_youtube_url(url) {
var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=v=|\&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