Get the FREE Ultimate OpenClaw Setup Guide →

regex-builder

Scanned
npx machina-cli add skill jmerta/codex-skills/regex-builder --openclaw
Files (1)
SKILL.md
1.8 KB

Regex builder

Goal

Produce a correct, testable regex with rationale and runnable verification.

Inputs to confirm (ask if missing)

  • Target regex flavor/engine (PCRE, Python, JavaScript, .NET, RE2, etc.).
  • Example matches and non-matches (at least 3 each when possible).
  • Scope: single-line vs multi-line; file types/paths.
  • Output needs: capture groups, named groups, replacement template.

Workflow

  1. Gather samples
    • Ask for sample text or identify files.
    • If files exist, locate with rg --files and preview with rg -n.
  2. Choose tool
    • Prefer rg for quick match checks; use rg -P for PCRE features.
    • Use Python for detailed group inspection when needed.
  3. Build incrementally
    • Start with a minimal literal anchor; expand piece by piece.
    • Add anchors/boundaries; handle whitespace and separators explicitly.
  4. Validate
    • Show a command to test against samples.
    • Confirm no false positives by testing non-matches.
  5. Deliver
    • Provide final regex, flags, and explanation.
    • Include a test command and expected match summary.
    • Note any tradeoffs/backtracking risks.

CLI snippets (use as needed)

  • Ripgrep check:
    • rg -n "<regex>" path\\to\\file
    • rg -n -P "<regex>" path\\to\\file
  • Python quick test (adjust quoting for the shell):
    • python -c "import re,sys;pat=re.compile(r'<regex>');data=sys.stdin.read();print([m.group(0) for m in pat.finditer(data)])" < path\\to\\file

Deliverables

  • Regex + flags and any capture group map.
  • Test command(s) and summary of matches/non-matches.
  • Short explanation of the approach and known limitations.

Source

git clone https://github.com/jmerta/codex-skills/blob/main/regex-builder/SKILL.mdView on GitHub

Overview

Regex-builder helps you craft correct, testable regular expressions against sample text or files. It guides you through flavor selection, incremental construction, and runnable verification with tools like rg and Python, ensuring you can validate matches, captures, and replacements end-to-end.

How This Skill Works

Start by collecting samples and choosing a flavor (PCRE, Python, etc.). Build the regex incrementally, test with rg commands or Python snippets, and then deliver the final pattern, flags, and a runnable test command plus a match summary.

When to Use It

  • You need to extract or validate patterns from a text corpus or codebase (for example emails, dates, or URLs).
  • You are debugging a failing regex in a script and want to inspect groups and matches precisely.
  • You must search across multiple files and confirm both matches and non-matches with representative samples.
  • You need to define capture groups and a replacement template for data normalization or templating.
  • You want to verify regex behavior across different engines and flavors (PCRE, Python, JavaScript, etc.).

Quick Start

  1. Step 1: Gather sample text or locate target files and decide the regex flavor (PCRE, Python, etc.).
  2. Step 2: Run a quick check with ripgrep to test a minimal literal pattern, using rg -n or rg -n -P for PCRE features.
  3. Step 3: Incrementally add capture groups and a replacement template, then run a final test command and review matches and non-matches.

Best Practices

  • Ask for the target regex flavor/engine up front to guide syntax and features.
  • Gather representative samples with at least 3 matching examples and 3 non-matching examples when possible.
  • Build the pattern incrementally from a minimal literal anchor, expanding piece by piece.
  • Prefer ripgrep (rg) for quick checks and switch to Python when you need detailed group inspection.
  • Deliver the final regex, flags, a capture map, a replacement template, test commands, and a summary of limitations.

Example Use Cases

  • Extract email addresses from log files and report matches with line numbers.
  • Validate and capture ISO date formats (YYYY-MM-DD) across a dataset for consistency.
  • Normalize phone numbers into a canonical format across multiple regional patterns.
  • Find and replace template placeholders like ${name} with actual values in documents.
  • Filter codebase lines that match a security-sensitive pattern using PCRE features.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers