Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remove protocol from URL
require 'uri'
url = 'http://google.com/'
def remove_protocol_from_url( url )
url = url[2..-1] if url.start_with?('//')
uri = URI(url)
if scheme = uri.scheme
url = url[scheme.length + 3..-1] # :// is 3 bytes
end
url
end
puts remove_protocol_from_url(url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment