Regex test cases: verify a pattern with a match table and ReDoS checks
Run a regex against should-match and should-not-match cases, show captured groups, and flag catastrophic-backtracking patterns with a timed stress test.
What it does
A procedure for never handing over an untested regex.
- Loads a case table in text form (
+ must match/- must not match) or JSON and runs the pattern with Pythonre - Prints PASS/FAIL, the match, span, and numbered and named groups for each case; JSON cases can also assert expected groups
- Statically flags catastrophic-backtracking (ReDoS) constructs such as nested quantifiers like
(a+)+or(\w+\s?)+and repeated overlapping alternatives - Runs every case in a worker process with a timeout so a runaway pattern cannot hang, and
--stresstimes risky fragments on growing input - Includes checks for common traps such as
$matching before a trailing newline and\dmatching full-width digits
How to use
python scripts/regex_test.py examples/postal.txt
python scripts/regex_test.py examples/email.json --stress
python scripts/regex_test.py --pattern "(a+)+$" --lint-only
Ask Claude, Codex, Hermes Agent or Cursor to write or fix a regex; it writes the test table first, iterates until every case passes, and delivers the pattern with the results.
Requirements
- Python 3.10+ (standard library only; atomic groups and possessive quantifiers need 3.11+)
Caveats
- Tests run on Python
re. Other engines such as JavaScript or Go differ in syntax and behavior; porting notes are part of the procedure. - The backtracking lint is heuristic. A clean result is not proof of safety, so keep long non-matching cases in the table.
- It only reads the case file; nothing is modified or sent over the network.
How to install
- Unzip the downloaded file (it contains a
regex-test-cases/folder withSKILL.md). - Copy the whole folder into your agent's skills folder.
- Claude:
~/.claude/skills/(per project:.claude/skills/) - Hermes Agent:
~/.hermes/skills/ - Codex:
~/.agents/skills// Cursor:~/.cursor/skills/ - Claude app (claude.ai): upload the ZIP in Customize → Skills
- Claude:
- Restart the agent and check that the skill appears in its skill list.
Seller
AI Skill Market (official)
44 published skills