Webflags: g

Cookie Header Value

Parse name=value pairs from an HTTP `Cookie:` header value.

Try it in RegexPro →

Available in

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("([^=;\\s]+)=([^;]+)", "g");
const input = "session=abc123; theme=dark; user_id=42";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).

Pattern

regexengine-agnostic
([^=;\s]+)=([^;]+)   (flags: g)

Raw source: ([^=;\s]+)=([^;]+)

How it works

([^=;\s]+) captures the cookie name — characters that aren't equals, semicolon, or whitespace. = is the literal separator. ([^;]+) captures the value — everything up to the next semicolon, allowing spaces and special chars inside the value. Repeats globally to capture every cookie.

Examples

Input

session=abc123; theme=dark; user_id=42

Matches

  • session=abc123
  • theme=dark
  • user_id=42

Input

single=value

Matches

  • single=value

Input

no cookies

No match

Common use cases

  • Reverse-proxy cookie inspection
  • Auth middleware that parses session cookies
  • Log analysis — extracting tracking cookies
  • Cookie-based feature gating in CDN edge logic

Related patterns