Regex to cut video id from youtube url
Sometimes we need to extract video ID from youtube url.
Here is my approch:
url = "//www.youtube-nocookie.com/embed/8sfzigidWqI?list=UUCZKJ_p08CuihXJQUF04Ljg\"
video_id = url.match(/(src=|src=\\)\"(\/\/|http:\/\/)?(www\.)(youtube.com|youtube-nocookie.com|youtu.be)\/embed\/(.{11})(.+)\"/)[5]
puts video_id
#=> "8sfzigidWqI"
Written by Roman Sotnikov
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#