Data, Prompts & Code Workbench

Regex Builder & Tester Agent

Stop guessing cryptic regular expression syntax through trial and error. Built for developers, QA analysts, and spreadsheet power users, this workbench generates engine-specific regex patterns from your match rules, explains every token and capture group in plain English, provides ready-to-run code snippets, and lists false-positive edge cases to test before deployment.

1. Configure Inputs

Stateful DO Session
Quick-fill sample:

2. Workbench Output & Refinements

Sample preview (#1) — click Run Agent for live output

Regex Pattern & Flags

\b([A-Z]{2,3}-20\d{2}-\d{5})\b

Token-by-Token Breakdown

  • \b (leading word boundary): Ensures ABCD-2026-00482 does not partially match its last three letters (BCD-...).
  • ([A-Z]{2,3}...): Capture group 1 containing the full invoice code for extraction.
  • [A-Z]{2,3}: Matches 2 or 3 uppercase ASCII letters (PO or INV).
  • -20\d{2}-: Matches a literal hyphen, 20 followed by two digits (2000-2099), and a second hyphen.
  • \d{5}: Matches exactly 5 digits for the serial number.
  • \b (trailing word boundary): Rejects 6+ digit strings like 0048249 while still matching when followed by a period or space.

Ready-to-Use Snippet

=IFERROR(REGEXEXTRACT(A2, "\b([A-Z]{2,3}-20\d{2}-\d{5})\b"), "")

Match Verification & Pitfalls

  • Matches: Paid: INV-2026-00482 -> extracts INV-2026-00482; Ref PO-2025-99104. -> extracts PO-2025-99104.
  • Rejects: INV-26-123 (year not 4 digits), inv-2026-0048249 (lowercase and 7 trailing digits), ABCD-2026-00482 (4 prefix letters blocked by leading \b).
  • RE2 compatibility: Uses standard word boundaries rather than lookbehinds, running linearly in Google Sheets.
You will get an engine-compatible regex pattern, a token-by-token explanation, a copy-ready code or formula snippet, and boundary edge-case checks.

Multi-Turn Refinement Chips (Same Session)

3 Curated Worked Examples

Inspect real sample inputs and structured deliverables for the Regex Builder & Tester Agent. Click Try in Workbench on any example to load its parameters into the form above.

Example 1: Extract structured invoice IDs in Google Sheets (RE2)

What pattern do you want to match, validate, or extract?: Extract invoice codes formatted as 2 or 3 uppercase letters, a hyphen, a 4-digit year s... Strings that SHOULD match and strings that SHOULD NOT match: Should match: 'Paid: INV-2026-00482', 'Ref PO-2025-99104.'. Should NOT match: 'INV-26-1... Regex engine / environment: Google Sheets / RE2 (Go) Tone: Clear & Methodical

Regex Pattern & Flags

\b([A-Z]{2,3}-20\d{2}-\d{5})\b

Token-by-Token Breakdown

  • \b (leading word boundary): Ensures ABCD-2026-00482 does not partially match its last three letters (BCD-...).
  • ([A-Z]{2,3}...): Capture group 1 containing the full invoice code for extraction.
  • [A-Z]{2,3}: Matches 2 or 3 uppercase ASCII letters (PO or INV).
  • -20\d{2}-: Matches a literal hyphen, 20 followed by two digits (2000-2099), and a second hyphen.
  • \d{5}: Matches exactly 5 digits for the serial number.
  • \b (trailing word boundary): Rejects 6+ digit strings like 0048249 while still matching when followed by a period or space.

Ready-to-Use Snippet

=IFERROR(REGEXEXTRACT(A2, "\b([A-Z]{2,3}-20\d{2}-\d{5})\b"), "")

Match Verification & Pitfalls

  • Matches: Paid: INV-2026-00482 -> extracts INV-2026-00482; Ref PO-2025-99104. -> extracts PO-2025-99104.
  • Rejects: INV-26-123 (year not 4 digits), inv-2026-0048249 (lowercase and 7 trailing digits), ABCD-2026-00482 (4 prefix letters blocked by leading \b).
  • RE2 compatibility: Uses standard word boundaries rather than lookbehinds, running linearly in Google Sheets.

Example 2: Validate semantic version tags with optional pre-release in JavaScript

What pattern do you want to match, validate, or extract?: Validate a full version string like v1.4.12 or 2.0.0-beta.1 (optional leading 'v', thre... Strings that SHOULD match and strings that SHOULD NOT match: Match: 'v1.4.12', '0.1.0', '2.0.0-beta.1'. Reject: 'v01.2.3', '1.2', '1.2.3.4', 'v1.2.3-'. Regex engine / environment: JavaScript / TypeScript (ECMAScript) Tone: Concise Developer

Regex Pattern & Flags

/^v?(?<major>0|[1-9]d*).(?<minor>0|[1-9]d*).(?<patch>0|[1-9]d*)(?:-(?<prerelease>[0-9A-Za-z-]+(?:.[0-9A-Za-z-]+)*))?$/

Token-by-Token Breakdown

  • ^v?: Anchors at the start of the string and allows an optional lowercase v.
  • *(?<major>0|[1-9]\d)**: Named capture group matching either a single 0 or a positive integer without leading zeros (rejecting v01.2.3). Repeated for minor and patch.
  • \.: Matches the literal dot separators between version numbers.
  • (?:-(?<prerelease>...))?$: Optional non-capturing outer group requiring a hyphen followed by one or more dot-separated alphanumeric identifiers, anchored to the end of the string ($).

Ready-to-Use Snippet

const SEMVER_RE = /^v?(?<major>0|[1-9]d*).(?<minor>0|[1-9]d*).(?<patch>0|[1-9]d*)(?:-(?<prerelease>[0-9A-Za-z-]+(?:.[0-9A-Za-z-]+)*))?$/;

export function parseVersion(input) {
  const match = SEMVER_RE.exec(input.trim());
  return match ? match.groups : null;
}

Match Verification & Pitfalls

  • Matches: v1.4.12, 0.1.0, and 2.0.0-beta.1 all match and populate match.groups.
  • Rejects: v01.2.3 (leading zero), 1.2 (missing patch), 1.2.3.4 (extra segment), and v1.2.3- (trailing hyphen with empty prerelease).

Example 3: Parse key-value log fields with optional quotes in Python

What pattern do you want to match, validate, or extract?: Extract key=value pairs from application log lines where the value is either a double-q... Strings that SHOULD match and strings that SHOULD NOT match: Match in: 'level=WARN service="checkout-api" msg="Card declined by issuer" latency_ms=1... Regex engine / environment: Python (re module) Tone: Security-Conscious

Regex Pattern & Flags

([a-zA-Z_][a-zA-Z0-9_]*)=("([^"\]*(?:\.[^"\]*)*)"|([^s"]+))

Token-by-Token Breakdown

  • *([a-zA-Z_][a-zA-Z0-9_])**: Group 1 captures the attribute key name starting with a letter or underscore.
  • =: Matches the literal equals separator.
  • *"([^"\\](?:\\.[^"\\]))"**: Unrolled loop that safely matches double-quoted values (including escaped quotes like \"), putting the inner text into Group 3 without catastrophic backtracking.
  • |([^\s"]+): Alternation branch capturing unquoted values (like WARN or 142) into Group 4.

Ready-to-Use Snippet

import re

TOKEN_RE = re.compile(r'([a-zA-Z_][a-zA-Z0-9_]*)=(?:"([^"\]*(?:\.[^"\]*)*)"|([^s"]+))')

def parse_log_line(line: str) -> dict[str, str]:
    return {m.group(1): (m.group(2) if m.group(2) is not None else m.group(3)) for m in TOKEN_RE.finditer(line)}

Match Verification & Pitfalls

  • Matches: Extracts {'level': 'WARN', 'service': 'checkout-api', 'msg': 'Card declined by issuer', 'latency_ms': '142'}.
  • Backtracking safety: The unrolled quote pattern [^"\\](?:\\.[^"\\])* evaluates linearly even on malformed log lines with an unclosed quote.

Practical Workflow Tips

How to get sharper, more reliable results from this workbench and verify output before publishing or shipping.

  • Always include 2 or 3 negative examples (strings that look close but must be rejected) so the agent sets the right word boundaries (\b) or line anchors (^ and $).
  • Select 'Google Sheets / RE2 (Go)' whenever your formula runs in Google Sheets, Looker Studio, or Cloudflare Workers rules, since RE2 rejects lookaheads and lookbehinds.
  • Prefer specific character classes like [^"\r\n]+ over greedy .* whenever matching inside delimiters so a single pattern does not swallow across multiple tokens on the same line.
  • If you are validating URLs, emails, or JSON payloads in application code, use your language's native parser (such as new URL() in JavaScript) and save regex for lightweight format pre-checks.

Frequently Asked Questions

Why does my regex work in JavaScript or regex testers but fail in Google Sheets?

Google Sheets uses Google's RE2 engine to guarantee linear execution time. Because of that design, RE2 intentionally omits PCRE and JavaScript features that can trigger exponential backtracking—specifically lookaheads ((?=...)), lookbehinds ((?<=...)), and backreferences (\1). Rewriting the pattern with a single capture group inside REGEXEXTRACT resolves the error.

What is the difference between validation anchors (^...$) and extraction boundaries (\b)?

Line anchors ^ and $ assert that the entire input string from start to finish matches your pattern, which is essential for form input validation. Word boundaries \b allow you to find and extract a matching code embedded inside a longer sentence while still preventing partial matches inside longer alphanumeric words.

What is catastrophic backtracking (ReDoS) and how do I avoid it?

Catastrophic backtracking happens when a regex engine evaluates nested repeating quantifiers like (a+)+ or (.+)* against a long string that almost matches but fails at the end. Avoid nesting quantifiers, replace dot-star with negated character classes like [^,]+, and cap input lengths before running complex regex checks.