Skip to content

Instantly share code, notes, and snippets.

@iansvo
Created April 9, 2019 20:21
Show Gist options
  • Save iansvo/c640b2ae52d778dea995ab2e2d15115f to your computer and use it in GitHub Desktop.
Save iansvo/c640b2ae52d778dea995ab2e2d15115f to your computer and use it in GitHub Desktop.
Get the ID of a YouTube video using it's URL. Returns false if no ID can be found.
function getYouTubeIdByUrl(url) {
var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/,
match = url.match(regExp),
result = false;
if( match && match[2].length == 11 ) {
result = match[2];
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment