Skip to content

Instantly share code, notes, and snippets.

@axelitus
Created August 24, 2012 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axelitus/3456158 to your computer and use it in GitHub Desktop.
Save axelitus/3456158 to your computer and use it in GitHub Desktop.
Named regex to match and split URI's according to IETF's STD 66
^(?#scheme)(?:(?P<scheme>[A-Za-z][A-Za-z0-9+\-.]*):)?
(?:(?#authority)//
(?#userinfo)(?:(?P<userinfo>.+)@)?
(?#host)(?P<host>(?:(?#named|IPv4)[A-Za-z0-9\-._~%]+|(?#IPv6)\[[A-Fa-f0-9:.]+\]|(?#IPvFuture)\[v[A-Fa-f0-9][A-Za-z0-9\-._~%!$&'()*+,;=:]+\])?)
(?#port)(?::(?P<port>[0-9]+))?
)?
(?#path)(?:/?(?P<path>(?:[A-Za-z0-9\-._~%!$&'()*+,;=@]+/?)*))?
(?#query)(?:\?(?P<query>[A-Za-z0-9\-._~%!$&'()*+,;=:@/?]*))?
(?#fragment)(?:\#(?P<fragment>[A-Za-z0-9\-._~%!$&'()*+,;=:@/?]*))?$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment