Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A simple ruby snippet to retrieve the id for a vimeo url.
# Simple ruby snippet to get the id for a vimeo url. This was based on this gist: https://gist.github.com/wwdboer/4943672
# This should be able to handle the following formats:
# http://vimeo.com/12345
# http://player.vimeo.com/video/12345
# http://player.vimeo.com/video/12345?test=value1
# http://player.vimeo.com/video/12345/?test=value1
# http://vimeo.com/channels/testchannel/12345
# http://vimeo.com/groups/testgroup/videos/1234
def vimeo_id(url)
match = url.match(/https?:\/\/(?:[\w]+\.)*vimeo\.com(?:[\/\w]*\/?)?\/(?<id>[0-9]+)[^\s]*/)
match[:id] if match.present?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment