Skip to content

Instantly share code, notes, and snippets.

View md-farhan-memon's full-sized avatar
🎯
Focusing

Md. Farhan Memon md-farhan-memon

🎯
Focusing
View GitHub Profile
@niquepa
niquepa / gist:4c59b7d52a15dde2367a
Last active January 25, 2023 23:51
Ruby rails extract youtube ID from URL
def youtube_id(youtube_url)
regex = /(?:youtube(?:-nocookie)?\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/
match = regex.match(youtube_url)
if match && !match[1].blank?
match[1]
else
nil
end
end