Skip to content

Web & Internet

URL & Query Parsing

The idea, in plain English

A URL (Uniform Resource Locator) is the web address you type or click. It often carries extra information after a question mark, called a query string, like /search?q=cats&limit=10. Parsing means splitting that text into a clean set of key-and-value pairs your program can use. It's like splitting a shopping list written as one long sentence into separate items.

How it works

  1. 1Split the URL at the '?'. Everything before it is the path. Everything after it is the query string.
  2. 2Split the query string at each '&'. That separates it into individual key=value pairs.
  3. 3Split each pair at its '=' to get the key on the left and the value on the right.
  4. 4Collect all the pairs into a simple lookup, like an object or dictionary, so your code can read params.q or params.limit directly.

When you'd use it

This applies when reading filters, search terms, page numbers, or IDs passed in a web address. Almost every search bar, filter dropdown, or 'page=2' link relies on query parsing.

Common beginner mistakes

  • Don't forget a URL might have no query string at all. Always check for the '?' before assuming there's anything to split.
  • A real parser must decode special characters, like %20 for a space. Our simplified version skips this, but production code must handle it.

Try it — edit and run

Click the code to edit · press ⌘/Ctrl+↵ to run

Editable code. Tab and Shift+Tab indent. Press Escape, then Tab, to move focus out of the editor.

Expected output — hit Run to try it
Full URL: /search?q=cats&limit=10
Path: /search
Query string: q=cats&limit=10
q = cats
limit = 10

Not sure this is the right topic? See the learning paths → or where this leads →