Created
May 10, 2014 22:53
-
-
Save arthuralee/338a3a185b54f4ab5a80 to your computer and use it in GitHub Desktop.
Get the youtube ID from a youtube URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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