Created
December 27, 2011 08:07
-
-
Save sunils34/1522996 to your computer and use it in GitHub Desktop.
Extract Youtube ID from Youtube URL
This file contains hidden or 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
//Given a youtube url, return the youtube id. | |
//There are several versions of youtube urls that work. | |
//http://www.youtube.com/v/0zM3nApSvMg?fs=1&hl=en_US&rel=0 | |
//http://www.youtube.com/embed/0zM3nApSvMg?rel=0 | |
//http://www.youtube.com/watch?v=0zM3nApSvMg&feature=feedrec_grec_index | |
//http://www.youtube.com/watch?v=0zM3nApSvMg | |
//http://youtu.be/0zM3nApSvMg | |
//http://www.youtube.com/watch?v=0zM3nApSvMg#t=0m10s | |
function extractYoutubeId(youtubeUrl) { | |
return youtubeUrl.match(/^.*((youtu.be\/)|(v\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment