Last active
August 29, 2016 20:32
-
-
Save derzunov/a6da7a4a6663b12542cbbfe071a3236c to your computer and use it in GitHub Desktop.
YouTube video id parser
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
link = "https://www.youtube.com/watch?v=Imeq3GeRttw" | |
link2 = "http://www.youtube.com/v/0zM3nApSvMg?fs=1&hl=en_US&rel=0" | |
link3 = "http://www.youtube.com/watch?v=EqS7oJcBi7w#t=0m10s" | |
youtube_parser = ( url ) -> | |
regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/ | |
match = url.match regExp | |
if match and match[7].length == 11 then match[7] else false | |
console.log youtube_parser( link ), youtube_parser( link2 ), youtube_parser( link3 ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment