URL query parameter regex pattern

Copy and test a JavaScript regex for URL query parameters, with examples, limitations, and a one-click link to the regex tester.

URL query parameter regex pattern

Validate whole value

Use anchors to check whether the complete value matches.

Regex: ^[^\s=&?#]+=[^\s#&]*$

Flags: -

Search in text

Find matching fragments inside a larger block of text.

Regex: [?&][^\s=&?#]+=[^\s#&]*

Flags: g

Examples that match

  • page=2
  • sort=desc

Examples that do not match

  • page
  • page 2

Limitations

This pattern is useful for simple key=value pairs. It does not decode percent-encoding or nested query syntaxes.