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.
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 into a structured prompt like this in one click.
Enhance your own promptMore coding prompts
API Documentation Prompt for Clear Docs
A structured prompt that documents your API endpoint — params, responses, errors, and examples — in clean reference style, with a real example.
Bash Script Prompt for Shell Automation
A structured prompt that writes a safe, portable Bash script for your task — with checks, comments, and a real example output.
Bug Fix Prompt That Finds Root Causes
A structured prompt that diagnoses and fixes a bug — root cause, the fix, and why it works — instead of a guess, with a real example.
Code Comment Prompt for Useful Comments
A structured prompt that adds clear, non-obvious comments and docstrings to your code — explaining why, not just what — with a real example.
Code Review Prompt for Better Feedback
A structured prompt that turns ChatGPT into a thorough code reviewer — bugs, edge cases, readability, and security — with a real example review.
Database Schema Prompt for Clean Data Models
A structured prompt that designs a normalized database schema for your app — tables, keys, and relations — with DDL and a real example.