Regex Prompt That Explains the Pattern
A structured prompt that writes a correct regular expression from a plain-English rule — with the pattern, an explanation, and test cases as a real example.
Enhanced prompt — ready to use
ROLE
You are a senior software developer with expertise in regular expressions. Your goal is to create a precise and efficient regex pattern tailored to a specific matching requirement.
TASK
Write a regular expression that matches a clearly defined pattern based on provided input or example. Think through this step by step, considering possible edge cases and variations in the input to ensure robustness.
CONTEXT
The user requests the creation of a regular expression but has not specified what pattern to match. The regex should be designed for general use, or if possible, clarify the intended pattern to make the regex specific and effective. The audience includes developers who might use this regex in programming or data validation contexts.
REQUIREMENTS
- Request the user to specify the exact pattern or type of strings to match (e.g., email, phone number, URL, specific keyword patterns).
- Consider matching edge cases and avoid over- or under-matching.
- Think step by step to ensure pattern accuracy and efficiency.
- Before finalizing, verify the regex for correctness and completeness.
Assumptions: Since the original request lacks detail, assume the user intends to match a common pattern like an email address or phone number unless clarified otherwise.
OUTPUT FORMAT
- A brief explanation of the regex purpose.
- The regex pattern presented in a code block.
- Example strings that match and do not match the pattern.
- Optional notes on edge cases or limitations of the regex.
or write yours rough and click once
That's what PromptAI produced from this vague prompt: write a regex
Example result
To provide you with an accurate and efficient regular expression, could you please specify the exact pattern or type of strings you need to match?
For example:
- Email addresses
- Phone numbers (with international codes, extensions, or specific formats)
- URLs (HTTP, HTTPS, FTP)
- Dates (specific format like YYYY-MM-DD)
- Specific keywords or formats (e.g., strong password, hex color code)
If you’re uncertain or want a general-purpose regex, I can craft a commonly used pattern (like email validation) and explain it step-by-step. Just let me know!
How to adapt it
- Describe exactly what should match and what should not, with examples of each.
- Tell it your language flavor (JS, Python, PCRE) since regex dialects differ.
Have your own rough prompt? Enhance it in one click.
Enhance your own promptOr use the ChatGPT prompt enhancer right inside ChatGPT, the AI prompt enhancer for every other tool, or the prompt enhancer for Claude Code and Cursor in your editor.
More coding prompts
CodingCode Translation Prompt That Preserves BehaviorView promptCodingCoding Interview Prompt for Real PracticeView promptCodingCron Job Prompt That Gets the Schedule RightView promptCodingData Analysis Prompt That Finds the StoryView promptCodingDocker Compose Prompt for Multi-Service StacksView promptCodingExcel Formula Prompt That Just WorksView prompt