Webflags: g

URL Query String

Extract the query string portion of a URL (everything between `?` and `#` or end-of-string).

Try it in RegexPro →

Available in

Pattern

regexengine-agnostic
\?([^#\s]+)   (flags: g)

Raw source: \?([^#\s]+)

How it works

\? matches the literal question mark. ([^#\s]+) captures everything up to (but not including) a `#` (fragment) or whitespace (URL boundary). Use URL parsing libraries for production, but this regex is handy for quick log scraping.

Examples

Input

https://example.com/page?utm_source=google&id=42

Matches

  • ?utm_source=google&id=42

Input

/api?token=abc#section

Matches

  • ?token=abc

Input

no query string here

No match

Common use cases

  • Log analysis — extracting tracking params
  • URL rewriting / canonicalisation tooling
  • Detecting PII leaked in query strings
  • Marketing attribution parsing