Regex architect
The largest community-driven library of Agent Skills (SKILL.md + scripts/references/examples) for Claude, Codex, Gemini CLI, Cursor and friends.
npx -y skills add JayRHa/AgentSkills --skill regex-architectAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 3 stars3 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Designs, explains, hardens, and tests regular expressions for parsing and validation tasks (emails, URLs, dates, IPs, log lines, CSV fields, identifiers, etc.) while actively defending against catastrophic backtracking (ReDoS). Use this skill when the user asks to "write a regex", "build/fix a regular expression", "match/extract/validate X with regex", "explain this regex", "why is my regex slow/hanging", check for "ReDoS"/"catastrophic backtracking", or convert a pattern between flavors (PCRE, Python re, JavaScript, Java, Go RE2, .NET). Covers capturing/named groups, anchors, lookarounds, Unicode, and flavor portability.
The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.
SKILL.md
6.9 KB, ~1.6k tokens by cl100k_base, as published. Nobody here has run it
Regex Architect
Overview
Build correct, readable, and safe regular expressions, then prove they work. Keywords: regex, regular expression, pattern matching, ReDoS, catastrophic backtracking, validation, extraction, capture group, named group, lookahead, lookbehind, anchor, Unicode, PCRE, RE2, flavor portability.
This skill exists because regex is easy to write and hard to write well. Naive patterns silently accept bad input, reject good input, or hang a server when fed an adversarial string. The job is not just "produce a pattern" — it is to produce a pattern that is anchored correctly, scoped to the right flavor, free of exponential backtracking, and accompanied by a test plan.
Use this skill whenever a task involves matching, extracting, replacing, splitting, or validating text with a pattern — or explaining/debugging an existing one.
Core Principles
- Clarify before constructing. Know the flavor, the input source, whether you are validating (whole string) or searching (substring), and what counts as valid. Ambiguity here produces wrong regexes.
- Anchor on purpose. Validation almost always needs
^...$(or\A...\z). Search/extract usually must NOT be anchored. Mismatched anchoring is the #1 correctness bug. - Prefer explicit character classes over
..is greedy, matches almost anything, and is a backtracking magnet. Use[^"],[^\n],\d, etc. - Make quantified subpatterns mutually exclusive. Overlapping alternations or
nested quantifiers (
(a+)+,(a|a)*,(.*)*) cause catastrophic backtracking. - Readability is a feature. Use named groups, verbose/extended mode, and comments for anything non-trivial. A regex nobody can edit is a liability.
- Validate with structured logic when regex is the wrong tool. Do not regex HTML, nested brackets, or full email RFC 5322. Say so and offer a parser.
Workflow
- Gather requirements (see
references/clarifying-questions.md):- Target flavor / language runtime.
- Validation vs. search vs. replace vs. split.
- Exact set of valid and invalid examples (ask for at least 2 of each).
- Multiline? Unicode? Case sensitivity? Performance constraints / untrusted input?
- Choose a strategy. Pick character classes, anchoring, and grouping. Consult
references/patterns-cookbook.mdfor vetted building blocks rather than inventing from scratch. - Draft the pattern in the requested flavor. Use named capture groups and, for non-trivial patterns, provide a verbose/commented version too.
- Audit for ReDoS using the checklist in
references/redos-guide.md. Rewrite nested/overlapping quantifiers; prefer atomic groups, possessive quantifiers, or bounded{0,n}quantifiers. If the runtime is RE2/Go/Rust, note it is already linear-time and lookarounds/backrefs are unsupported. - Explain it. Provide a token-by-token breakdown so the user can maintain it.
- Test it. Run
scripts/regex_test.pywith positive and negative cases. It also runs a lightweight ReDoS timing probe. Report pass/fail per case. - Note portability. If the user may switch flavors, flag flavor-specific
constructs (lookbehind, named-group syntax,
\dUnicode semantics, inline flags) perreferences/flavor-portability.md.
Quick Decision Framework
- "Is this string entirely valid?" → anchor with
^$(or\A\z); usere.fullmatchin Python. - "Find all occurrences." → no anchors; use global/
findall; mind overlapping matches. - "Untrusted/large input?" → prioritize linear-time design; consider RE2-family engine; cap input length before matching.
- "Nested or recursive structure (HTML, JSON, code)?" → do NOT use regex; use a parser.
- "Just needs a yes/no on a simple format?" → small anchored class-based pattern.
Worked Example (short)
Validate a US ZIP (5 digits, optional -####), JavaScript:
/^\d{5}(?:-\d{4})?$/
^/$anchor the whole string.\d{5}exactly five digits.(?:-\d{4})?optional non-capturing group: hyphen + four digits.
Why it is ReDoS-safe: fixed-count quantifiers, no nested/overlapping repetition.
See examples/worked-example.md for a full email-validation walkthrough including
a naive-vs-safe comparison and test output.
Best Practices
- Always provide both the raw pattern and a one-line explanation of anchoring intent.
- Use non-capturing groups
(?:...)unless you need the capture; name the ones you keep. - For validation, return whole-string semantics explicitly (
fullmatch,\A...\z, or^...$with the right flags). - Escape user-provided literals; never interpolate raw user input into a pattern.
- Cap input length and/or set engine timeouts when matching untrusted data.
- Offer a verbose/
x-mode version for any pattern longer than ~40 chars. - Prefer
[0-9]over\dwhen you must exclude non-ASCII digits (\dmatches Unicode digits in many flavors).
Common Pitfalls
- Unanchored validation —
/\d{5}/matches insideabc12345xyz. Anchor it. - Greedy
.*across delimiters —<.*>over<a><b>grabs everything; use<[^>]*>or lazy<.*?>with care. - Nested quantifiers —
(\d+)+,(a*)*,(.*,)*→ catastrophic backtracking. - Unescaped dot/metachars in literals —
3.14matches3x14; escape to3\.14. ^/$with multiline — they match line boundaries underm; use\A/\z(or\Z) for true string ends.- Backreferences/lookbehind in RE2/Go/Rust — unsupported; redesign.
- Trying to regex HTML/recursive grammars — wrong tool; use a parser.
\bword-boundary surprises — depends on\wdefinition and Unicode mode.
Bundled Files
references/patterns-cookbook.md— vetted, safe patterns for common formats with notes and traps.references/redos-guide.md— how catastrophic backtracking happens and how to fix it.references/flavor-portability.md— cross-flavor syntax differences and a mapping table.references/clarifying-questions.md— the question set to ask before writing a pattern.scripts/regex_test.py— runnable Python tester for positive/negative cases plus a ReDoS timing probe.examples/worked-example.md— end-to-end email-validation example with test output.
What ships with it: 6 files
23.3 KB alongside SKILL.md, 1 of them executable
examples/
- worked-example.md3.2 KB
references/
- clarifying-questions.md2.0 KB
- flavor-portability.md3.3 KB
- patterns-cookbook.md4.1 KB
- redos-guide.md4.1 KB
scripts/
- regex_test.pyruns6.6 KB