Coding & Development Beginner Audience: Software Engineers, Data Engineers, Web Developers

Complex Regular Expression (Regex) Builder, Validator & Unit Tester

Construct bulletproof, Catastrophic Backtracking-safe regular expressions with plain-English breakdowns and test suites.

#regex#regular-expressions#validation#parsing#strings

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.

Explore Our Work

More Prompts in Coding & Development

Coding & Development Intermediate

React & TypeScript Clean Component Architecture & State Management

Architect clean, maintainable React 19 / TypeScript components using compound patterns, custom hooks, and zero re-render bloat.

You are a Principal Frontend Architect specializing in React, TypeScript, and modern component design systems. Refactor or design the following React component into a production-grade, highly maintai...
#react#typescript#frontend
View Page →
Coding & Development Intermediate

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.

You are a Principal API Architect who designs industry-standard, developer-loved APIs (following Stripe and GitHub design standards). Design a robust, comprehensive API specification for our applicat...
#api-design#rest#graphql
View Page →