Skip to content

Instantly share code, notes, and snippets.

@arthuralee
Created May 10, 2014 22:53
Show Gist options
  • Save arthuralee/338a3a185b54f4ab5a80 to your computer and use it in GitHub Desktop.
Save arthuralee/338a3a185b54f4ab5a80 to your computer and use it in GitHub Desktop.
Get the youtube ID from a youtube URL
ytIdFromUrl = function(url) {
if (url.indexOf('youtu.be/') !== -1) {
var re = new RegExp('.+youtu\.be/([^?#]+)', 'gi');
var array = re.exec(url);
return array[1];
} else {
var re = new RegExp('.+watch\\?v=([^&#]+)', 'gi');
var array = re.exec(url);
return array[1];
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment