Complex Regular Expression (Regex) Builder, Validator & Unit Tester
Construct bulletproof, Catastrophic Backtracking-safe regular expressions with plain-English breakdowns and test suites.
System Directive • Copy and Paste Below
You are an expert compiler engineer and regular expression (regex) specialist.
Construct a robust, safe, high-performance regular expression to parse and validate the following string pattern.
### PATTERN SPECIFICATIONS:
- Target Pattern to Match: [DESCRIBE_PATTERN_E_G_INTERNATIONAL_PHONE_NUMBERS_SEMVER_URL_PARSING]
- Regex Flavor (JavaScript / PCRE / Python / Golang): [REGEX_FLAVOR]
- Valid Examples that MUST Match:
1. [VALID_EXAMPLE_1]
2. [VALID_EXAMPLE_2]
3. [VALID_EXAMPLE_3]
- Invalid Examples that MUST NOT Match:
1. [INVALID_EXAMPLE_1]
2. [INVALID_EXAMPLE_2]
3. [INVALID_EXAMPLE_3]
### DELIVERABLES:
1. **The Production Regex String**:
- Clean regex with appropriate flags (e.g. `g`, `m`, `i`, `u`).
- Using named capture groups (e.g. `(?<country_code>\+\d{1,3})`) for clean, self-documenting code.
2. **Plain-English Token-by-Token Breakdown**:
- Explaining exactly what every character, quantifier, group, and assertion is doing.
3. **Catastrophic Backtracking (ReDoS) Vulnerability Check**:
- Verifying that nested quantifiers like `(a+)+` are absent and that the regex runs in linear O(N) time.
4. **Implementation Code Snippet**:
- Complete helper function in [REGEX_FLAVOR] extracting named groups into a typed dictionary / object.
5. **Unit Test Suite**:
- Verification asserting true for all valid examples and false for all invalid examples.
Customization & Placeholders
Provide at least 3 valid and 3 invalid examples. The prompt validates against ReDoS (Regular Expression Denial of Service).
Example Input Values
Pattern: Semantic Version strings with optional v prefix and build metadata, Flavor: JavaScript, Valid: v1.0.0, 2.4.1-beta.2, Invalid: 1.0, v1.0.0.0, beta-1.
Expected Output Structure
Named capture group regex, detailed token breakdown, ReDoS safety audit, and JavaScript utility function.
Custom Software Engineering by Qubenix
Qubenix builds robust, bug-free web applications and data processing pipelines engineered for scale.
More Prompts in Coding & Development
React & TypeScript Clean Component Architecture & State Management
Architect clean, maintainable React 19 / TypeScript components using compound patterns, custom hooks, and zero re-render bloat.
PostgreSQL / MySQL Query Optimization, Indexing & EXPLAIN ANALYZE
Diagnose slow database queries, optimize table schemas, and design composite B-Tree/GIN indexes to drop execution time by 90%+.
Enterprise REST & GraphQL API Schema Designer with OpenAPI Specs
Design clean, pragmatic RESTful endpoints or GraphQL schemas adhering to OpenAPI 3.1 standards, pagination, and status codes.