Created
September 16, 2013 20:30
-
-
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).
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
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