Skip to content

Instantly share code, notes, and snippets.

@wycats
Created May 5, 2010 10:06
Show Gist options
  • Save wycats/390597 to your computer and use it in GitHub Desktop.
Save wycats/390597 to your computer and use it in GitHub Desktop.
url = %r{
^
([A-Za-z]*) # scheme (e.g. http)
:
//? # mailto: and news: URLs do not require forward slashes
([0-9.\-A-Za-z@]*) # domain (e.g., www.regexml.org)
(?: # port number
:
(\d{0,5})
)?
( # resource (e.g., /sample/resource)
/[^?#]*
)?
(?: # query string
\?([^#]*)
)?
(?:
\#(.*) # anchor tag
)?
$
}x
p url.match("scheme://domain.com:8808/sample/resource?query=string#anchor").to_a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment