← Home

regex

Deterministic regex evaluation for AI agents.

An LLM asked whether a regex matches will simulate the engine in its head — and get it wrong on greediness, anchoring, capture groups, and Unicode boundaries. Euclid's regex tool executes patterns against real strings with a real engine (RE2, linear-time safe). Test, match, extract, replace, and split — every result is computed, not predicted.


Live

euclid / regex
regex({ operation: "test", pattern: "^\d{3}-\d{4}$", subject: "555-1234" }){ "match": true }
regex({ operation: "match", pattern: "(?<user>\w+)@(?<domain>[\w.]+)", subject: "admin@example.com" }){ "match": "admin@example.com", "groups": { "user": "admin", "domain": "example.com" } }
regex({ operation: "matchAll", pattern: "\d+", subject: "abc 123 def 456 ghi 789" }){ "matches": ["123", "456", "789"], "count": 3 }
regex({ operation: "replace", pattern: "\s+", flags: "g", subject: "hello world foo", replacement: " " }){ "result": "hello world foo" }

Operations

testmatchmatchAllreplacesplitescapenamed groupspositional capturesflags (g, i, m, s)

Examples

What it looks like in practice

Validating a phone number format

regex({ operation: "test", pattern: "^\d{3}-\d{4}$", subject: "555-1234" })

{ "match": true }

Extracting email parts with named groups

regex({ operation: "match", pattern: "(?<user>\w+)@(?<domain>[\w.]+)", subject: "admin@example.com" })

{ "match": "admin@example.com", "groups": { "user": "admin", "domain": "example.com" } }

Finding all numbers in a log entry

regex({ operation: "matchAll", pattern: "\d+", subject: "abc 123 def 456 ghi 789" })

{ "matches": ["123", "456", "789"], "count": 3 }

Normalising whitespace in user input

regex({ operation: "replace", pattern: "\s+", flags: "g", subject: "hello world foo", replacement: " " })

{ "result": "hello world foo" }

Splitting a CSV row by delimiters

regex({ operation: "split", pattern: "[,;]+\s*", subject: "apples, bananas; cherries, dates" })

{ "parts": ["apples", "bananas", "cherries", "dates"] }

Escaping user input for safe regex embedding

regex({ operation: "escape", subject: "price is $10.00 (USD)" })

{ "result": "price is \$10\.00 \(USD\)" }


Who uses this

Built for agents across every domain

fn()

Backend engineer

An agent parsing structured log lines with capture groups — where a misplaced quantifier silently drops half the fields.

fn()

Data engineer

Cleaning CSV data with regex replacements — normalising phone numbers, stripping HTML tags, and splitting multi-value fields.

fn()

Security analyst

Testing whether user input matches known injection patterns. A false negative means a missed vulnerability.

fn()

Content moderator

An AI agent extracting URLs, emails, and mentions from user-submitted text using patterns that must handle Unicode and edge cases.

fn()

DevOps engineer

Parsing version strings, container tags, and CI log output — where a greedy match silently captures the wrong artifact.

fn()

Legal tech developer

Extracting clause numbers, dates, and party names from contracts using regex that must handle inconsistent formatting.


Try regex on Euclid Cloud

One MCP connection. Every computation your agents need.

Get started