Write a Regex Pattern
Generate accurate, explained regular expressions for any pattern-matching task with test cases.
The Prompt
Write a regular expression that matches the following pattern. Include: 1. The regex pattern itself 2. A plain-English explanation of each part of the regex 3. 5+ test cases showing what it should and should not match 4. Any important flags needed (global, case-insensitive, multiline) 5. A note about any edge cases or known limitations Pattern to match: [DESCRIBE WHAT YOU WANT TO MATCH — e.g., US phone numbers in formats (555) 123-4567, 555-123-4567, 5551234567] Language/engine: [JAVASCRIPT/PYTHON/RUBY/etc.]
Example Output
Pattern: `/^(\+1[-\s]?)?\(?([0-9]{3})\)?[-\s]?([0-9]{3})[-\s]?([0-9]{4})$/` — matches US phone numbers in all common formats including optional country code, with or without parentheses around area code, and any separator (space, hyphen, or none).
FAQ
Which AI model is best for Write a Regex Pattern?
GPT-4o works well for regex. Claude Sonnet 4 provides more thorough explanations of complex patterns.
How do I use the Write a Regex Pattern prompt?
Copy the prompt, replace the [BRACKETED] placeholders with your specific information, and paste into your preferred AI assistant (ChatGPT, Claude, Gemini, etc.). Pattern: `/^(\+1[-\s]?)?\(?([0-9]{3})\)?[-\s]?([0-9]{3})[-\s]?([0-9]{4})$/` — matches US phone numbers in all common formats including optional country code, with or without parentheses around area code, and any separator (space, hyphen, or none).
Model Recommendation
GPT-4o works well for regex. Claude Sonnet 4 provides more thorough explanations of complex patterns.