By Steven Levithan on Oct 24, 2008


This function splits any well-formed URI into its parts (all are optional). All parts are split with a single regex using backreferences, and all groupings which don’t contain complete URI parts are non-capturing.

Try the demonstration


  • Created by: Steven Levithan
  • Web Site:
  • Posted: October 24, 2008


  • Comprehensively splits URIs, including splitting the query string into key/value pairs.
  • Two parsing modes: loose and strict.
  • Offers convenient, pre-concatenated components (path = directory and file; authority = userInfo, host, and port; etc.)
  • Change the default names of URI parts without editing the function, by updating parseUri.options.key.

Blog post

Source Code

Paste this source code into the designated areas.

External file

Paste this code into an external JavaScript file named: parseuri.js


Paste this code into the HEAD section of your HTML document.