Last active
December 12, 2015 09:19
-
-
Save selimb86/4751026 to your computer and use it in GitHub Desktop.
This snippets show how to extract the video id of a youtube video from its 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
// Source : http://stackoverflow.com/questions/3452546/javascript-regex-how-to-get-youtube-video-id-from-url | |
var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?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