Created
August 2, 2014 16:00
-
-
Save murugan-r/bf59d6b373f513c6544e to your computer and use it in GitHub Desktop.
More strict web URL regex for validations. (better then URI.regexp)
This file contains hidden or 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
require 'uri' | |
hostname = "(?:(?:[\\w\\-]+\\.)+[[:alpha:]]{2,})" | |
host = "(?:#{hostname}|#{URI::DEFAULT_PARSER.pattern[:IPV4ADDR]}|#{URI::DEFAULT_PARSER.pattern[:IPV6ADDR]})" | |
server = "//(?:#{URI::DEFAULT_PARSER.pattern[:USERINFO]}@)?#{host}(?::\\d*)?" | |
absolute_path = "(?:#{URI::DEFAULT_PARSER.pattern[:ABS_PATH]})?" | |
query = URI::DEFAULT_PARSER.pattern[:QUERY] | |
http_uri_regex = Regexp.new("\\A(?:http|https):(?:#{server}#{absolute_path})(?:\\?(?:#{query}))?\\z", Regexp::EXTENDED, 'N') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment