Skip to content

Instantly share code, notes, and snippets.

@salbito
Created January 22, 2010 00:44
Show Gist options
  • Save salbito/283374 to your computer and use it in GitHub Desktop.
Save salbito/283374 to your computer and use it in GitHub Desktop.
def getUriQuery(url)
dots = url.scan(/\./)
dotsSize = dots.size
httpRegex = '(?![https?:\/\/])'
minimumUriRegex = '([^.]+\.[^.]+\...|[^.]+\.[^.]+)$' # Credit to @blaines
dotsSize -= 1
appendableRegex = '[^.]+\.'*dotsSize
customUriRegex = minimumUriRegex.insert(18, appendableRegex).insert(1, appendableRegex)
fullUriRegex = httpRegex + customUriRegex
uriToQuery = url.slice(Regexp.new(fullUriRegex))
return uriToQuery
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment