Created
April 9, 2019 20:21
-
-
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.
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
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