Created
January 22, 2010 00:44
-
-
Save salbito/283374 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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