Skip to content

Instantly share code, notes, and snippets.

@murugan-r
Created August 2, 2014 16:00
Show Gist options
  • Select an option

  • Save murugan-r/bf59d6b373f513c6544e to your computer and use it in GitHub Desktop.

Select an option

Save murugan-r/bf59d6b373f513c6544e to your computer and use it in GitHub Desktop.

Revisions

  1. murugan-r created this gist Aug 2, 2014.
    9 changes: 9 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    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')