- Home
- Skills
- Code Quality & Review
- Regex Builder Explainer and Tester with ReDoS Check
Works with the AI Agents you already use
Regex Builder Explainer and Tester with ReDoS Check
Build, explain and test regular expressions for your exact flavor, run real pass/fail tests, catch ReDoS, get paste-ready code. Verdict SAFE / RISKY / REWRITE.
$5
Regex Builder Explainer and Tester with ReDoS Check
Example session with this skill installed
Our Node API validates usernames with /^([a-zA-Z0-9]+[._-]?)+$/ and a security scan flagged it as ReDoS. Usernames are 3-20 chars, letters and digits, with a single . _ or - allowed only between alphanumerics. Fix it, and give me the same rule for our Go service.
- Read your context and instructions
- Compiled the regex builder explainer
Regex: username validation · Flavor: JavaScript (Node 22) + Go RE2 · Verdict: REWRITE
Spec: 3-20 chars, ASCII letters/digits, single . _ or - only between alphanumerics · Mode: full-string · Examples: user-supplied + generated
Why REWRITE
^([a-zA-Z0-9]+[._-]?)+$ nests a + inside a + with an optional separator, so aaaa can be split many ways. Measured in Node 22 on "a"*n + "!":
| n | time |
|---|---|
| 20 | 7.46 ms |
| 24 | 128.04 ms |
| 28 | 2156.71 ms (stopped) |
It also has no length limit.
Pattern (JS)
^(?=.{3,20}$)[a-zA-Z0-9]+(?:[._-][a-zA-Z0-9]+)*$
| Token | Meaning |
|---|---|
(?=.{3,20}$) | lookahead: total length 3-20 |
[a-zA-Z0-9]+ | starts with 1+ alphanumerics |
(?:[._-][a-zA-Z0-9]+)* | each separator must be followed by alphanumerics |
$ | end of string |
Every character now has exactly one path, so there is no blowup: same input at n=28 ran in 0.00 ms.
Tests (Node 22, rxtest.mjs)
| Input | Expect | Result |
|---|---|---|
sam, data_owner, a.b-c_d, user2026, 20-char name | match | PASS x5 |
ab, .sam, sam., a..b, a._b, 21-char name, sam doe, sam! | no match | PASS x8 |
13/13 passed
Paste-ready code
const USERNAME = /^(?=.{3,20}$)[a-zA-Z0-9]+(?:[._-][a-zA-Z0-9]+)*$/;
export const validUsername = (s) => USERNAME.test(s);
Go's RE2 rejects (?= (tested: "invalid or unsupported Perl syntax"), so the length check moves into code:
var usernameRe = regexp.MustCompile(`^[a-zA-Z0-9]+(?:[._-][a-zA-Z0-9]+)*$`)
func validUsername(s string) bool {
return len(s) >= 3 && len(s) <= 20 && usernameRe.MatchString(s)
}
Go run: same 13 cases, 13/13 passed. RE2 is linear-time, so no ReDoS check needed there.
Notes
- ASCII only by design; non-ASCII names fail in both versions.
- Go
lencounts bytes, which equals characters here because the pattern only allows ASCII.
Connects securely to your tools. The creator never sees your data.
About this skill
Regex answers from a chat window often look right and fail in production: lookbehind that Go rejects, \d that means something different in Python and JavaScript, a pattern that never got tested against the strings that should NOT match, or a nested quantifier that hangs your API on a 30-character input.
This skill gives your coding agent a fixed routine for regular expressions:
- Asks once for flavor, examples and mode, then proceeds with stated defaults
- Checks the target flavor first (JavaScript, Python re, PCRE/PHP, Java, .NET, Go RE2, Rust regex, POSIX grep/sed/awk, ripgrep) using a reference matrix of lookaround, backreference, named-group and Unicode differences
- Explains any pattern token by token in a table
- Runs a must-match / must-not-match test table in the shell with included Python and Node harnesses, and reports only results it actually ran
- Scans for catastrophic backtracking shapes and measures suspect patterns with a bounded timing loop, then offers a safe rewrite
- Outputs paste-ready code with correct escaping for the host language (raw strings, JS literals, Java and JSON double escaping, PHP delimiters, shell quoting)
- Warns when regex is the wrong tool (HTML, nested structures, full email RFC validation) and names the right one
- Ends with a SAFE, RISKY or REWRITE verdict
Who it's for: developers writing input validation, log searches, data cleaning or config rules, and anyone porting a pattern between languages or responding to a ReDoS finding.
Honesty note: the skill tells the agent never to report a pass, a fail or a timing it did not run. Flavor facts in the reference file were checked against official docs in October 2026, with sources listed; engines change, so rows that may shift are marked for re-checking.
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Code Quality & Review.
Test results depend on the regex engines installed in your shell; when the exact runtime is missing, the agent tests in the closest engine and says which. ReDoS timing is a measured check, not a formal guarantee. Flavor facts were verified in October 2026 and may change with new engine versions. It does not replace a parser for HTML, JSON or other nested formats.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 1 month ago