- Home
- Skills
- APIs & Backend
- regex generator
Works with the AI Agents you already use
regex generator
Generate engine-optimized, ReDoS-safe regular expressions with segment breakdowns and performance audits.
$6
regex generator
Example session with this skill installed
Generate a regex for a US phone number in (XXX) XXX-XXXX or XXX-XXX-XXXX format. Target engine is Python. Must not allow area codes starting with 0 or 1.
- Read your context and instructions
- Compiled the regex generator
I have generated a Python-compatible regex for US phone numbers that strictly enforces the requirement that area and exchange codes cannot start with 0 or 1.
Final Regex
r"^(?:\([2-9][0-9]{2}\)\s|[2-9][0-9]{2}-)[2-9][0-9]{2}-[0-9]{4}$"
Segment Breakdown
| Segment | Meaning | Design reason |
|---|---|---|
^ | Start anchor | Ensures the entire string is validated. |
(?:...|...) | Non-capturing group | Groups the two allowed prefix formats without overhead. |
\([2-9][0-9]{2}\)\s | (XXX) format | Matches area codes 200-999 followed by a space. |
[2-9][0-9]{2}- | XXX- format | Matches area codes 200-999 followed by a hyphen. |
[2-9][0-9]{2} | Exchange code | Matches second group starting with 2-9. |
- | Hyphen | Literal separator. |
[0-9]{4}$ | Subscriber number | Matches 4 digits and requires the end of the string. |
Test Cases
Positives (should match)
| Input | Expected match | Notes |
|---|---|---|
| (212) 555-1234 | Full match | Standard parentheses format. |
| 212-555-1234 | Full match | Standard hyphen format. |
| (999) 999-9999 | Full match | Boundary check for high digits. |
Negatives (should not match)
| Input | Expected result | Notes |
|---|---|---|
| (012) 555-1234 | No match | Area code starts with 0. |
| 112-555-1234 | No match | Area code starts with 1. |
| 212-055-1234 | No match | Exchange code starts with 0. |
| 212-555-123 | No match | Missing final digit. |
Edge-Case Pitfalls
Unicode Digits: This regex uses [0-9] instead of \d to prevent Python from matching non-ASCII digits like ١.
2. Whitespace: Only a literal space is allowed after the closing parenthesis; if tabs are possible, use \s.
Cross-Engine Differences
| Feature | PCRE | JavaScript | Python re | Java | Go RE2 |
|---|---|---|---|---|---|
| Lookahead | ✅ | ✅ | ✅ | ✅ | ❌ |
| Atomic Groups | ✅ | ❌ | ✅ (3.11+) | ✅ | ❌ |
Performance Risk
- Risk level: Low
- Analysis: The regex is linear and anchored. There are no nested quantifiers.
- Measured runtime magnitude: ~0.01ms for standard inputs.
- Optimisation advice: None required. The alternation is distinct and non-overlapping.
Next steps
- Integrate the raw string
r""into your Python validation logic. - Run the provided positive test cases in your unit test suite.
- If you need to support international prefixes, provide the specific country codes.
Connects securely to your tools. The creator never sees your data.
About this skill
Regex authoring is notoriously error-prone, leading to silent validation failures or catastrophic backtracking that can take down a production server. This skill converts natural-language requirements into precise, engine-optimized regular expressions with full performance audits.
What it does
- Multi-engine generation produces syntax tailored for PCRE, JavaScript, Python, Java, or Go RE2.
- Backtracking analysis identifies nested quantifiers and provides measured runtime estimates to prevent ReDoS.
- Structural breakdown explains every segment, anchor, and group to ensure maintainability.
- Automated test suite generates positive and negative test cases covering boundary conditions and Unicode edge cases.
- Refactoring & optimization analyzes existing complex patterns to reduce complexity and improve execution speed.
How it works
- Provide a plain-language description of your matching requirement and optional sample text.
- Specify your target programming language or regex engine to ensure syntax compatibility.
- Review the generated regex, the segment breakdown table, and the performance risk assessment.
- Verify the results against the provided positive and negative test cases.
Frameworks & tools
Supports PCRE, ECMAScript (JS), Python re and regex modules, Java java.util.regex, and Go regexp (RE2).
Why this beats prompting it yourself
Generic prompts often produce patterns that "look right" but fail on Unicode digits or crash under load due to exponential backtracking. This skill uses a defensive methodology, replacing risky \d shortcuts with explicit [0-9] classes and providing specific runtime magnitudes for performance-critical paths.
Use cases
- Validating complex inputs like SSNs, IBANs, or localized phone numbers.
- Extracting structured data from unstructured logs or Markdown files.
- Refactoring legacy regex strings to remove ReDoS vulnerabilities.
- Writing cross-platform patterns that work identically in Go and JavaScript.
Known limitations
Cannot execute or live-test patterns against a real-time data stream. Does not generate non-regex parsers for deeply nested structures like recursive HTML or JSON.
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for APIs & Backend.
Cannot execute patterns against live data. Does not support non-regex parsers for recursive structures. Requires error messages for debugging existing code.
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 today
- Software
Python
Describe what you want to match and paste a sample of the target text. Name the target engine (JavaScript, Python, PCRE, Java, Go) for engine-specific output.
Permissions
No special permissions declared or detected