Cookie Header Value
Parse name=value pairs from an HTTP `Cookie:` header value.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
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).
Python (re) code
import re
pattern = re.compile(r"([^=;\s]+)=([^;]+)")
input_text = "session=abc123; theme=dark; user_id=42"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`([^=;\s]+)=([^;]+)`)
input := `session=abc123; theme=dark; user_id=42`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
Pattern
([^=;\s]+)=([^;]+) (flags: g)Raw source: ([^=;\s]+)=([^;]+)
How it works
Examples
Input
session=abc123; theme=dark; user_id=42Matches
session=abc123theme=darkuser_id=42
Input
single=valueMatches
single=value
Input
no cookiesNo 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
HTTP Content-Type Header
WebParse the value of an HTTP Content-Type header, capturing the media type and optional charset.
HTML Attribute
WebMatch HTML attributes of the form name="value" or name='value' and capture both parts.
HTML5 Color Input Value
WebValidate the value of an HTML5 `<input type="color">` — exactly 6 hex digits with leading hash.
CSS Class from `class=""` Attribute
WebExtract the value of a `class="..."` attribute from raw HTML, handling double or single quotes.