AI Prompts Library

Curated collection of expert prompts for coding, writing, marketing, image generation, and more

Have a great prompt? Submit it to the library →

Coding

Regex Pattern Builder and Explainer

Optimized for: general • TEXT
You are a regex expert who creates, explains, and debugs regular expressions. Help with the described pattern matching need.

**What to Match:** [DESCRIBE WHAT YOU WANT TO MATCH]
**Programming Language:** [JavaScript / Python / Go / Java / PHP / Ruby / .NET]
**Sample Input:** [PROVIDE SAMPLE STRINGS THAT SHOULD AND SHOULD NOT MATCH]

**Provide:**

1. **The Regex Pattern:**
   - Provide the complete pattern with proper delimiters for the language
   - Include necessary flags (global, case-insensitive, multiline)
   - If the pattern has capture groups, explain what each group captures

2. **Visual Breakdown:**
   - Break the regex into segments
   - Explain each segment in plain English
   - Use a character-by-character walkthrough for complex parts
   - Show the pattern as a railroad diagram description

3. **Test Cases:**
   - 5 strings that SHOULD match (with explanation of what is captured)
   - 5 strings that should NOT match (with explanation of why)
   - Edge cases to be aware of

4. **Usage Example:**
   - Complete code snippet showing the regex in use
   - Include: matching, extracting groups, replacing, and splitting examples
   - Show how to handle the match result properly

5. **Performance Notes:**
   - Warn about catastrophic backtracking risks
   - Suggest non-capturing groups where capture is not needed
   - Recommend possessive quantifiers or atomic groups if supported
   - Alternative approach if regex is not the best tool for this job

6. **Common Variations:**
   - Provide a stricter version that rejects more edge cases
   - Provide a more lenient version that accepts more formats
   - Show how to make the pattern Unicode-aware if relevant

**Output**: The regex pattern, visual explanation, test cases, and ready-to-use code snippet.

Input validation, text parsing, data extraction, log analysis, search and replace

Want Custom Prompts?

Get personalized AI prompts tailored to your specific needs and workflow.

Contact Us