The prompt
Write a regular expression to match [PATTERN DESCRIPTION] What it is
Regex Writer is a minimal but highly practical prompt that lets you describe a text pattern in plain English and get back a working regular expression. Regular expressions are powerful but have notoriously cryptic syntax, and even experienced developers often need to look up specific constructs. This prompt turns the AI into a regex assistant: you describe what you want to match (email addresses, phone numbers, date formats, specific log patterns, etc.) and the AI produces the expression. It eliminates the trial-and-error cycle of building regex patterns manually. For best results, be as precise as possible about your requirements. Mention edge cases, whether the match should be anchored, and which regex engine you are targeting. The more context you provide, the more accurate the generated expression will be.
Who it's for
- Developers
- Data engineers working with text parsing and validation
Requirements
Requirements
- Any AI chatbot (ChatGPT, Claude, Gemini)
برومبت يطلب من الذكاء الاصطناعي كتابة تعبير نمطي (Regex) يطابق نمطا معينا بناء على وصف بالكلمات.
Examples
From the source
PromptWrite a regular expression to match [PATTERN DESCRIPTION]Expected output: From PickleBoxer's dev-chatgpt-prompts collection on GitHub.
Pros & cons
Pros
- Pro:Regex syntax is notoriously hard to remember, so this saves significant lookup time
- Pro:The AI can handle complex patterns that would take many iterations to get right manually
Cons
- Con:Regex generated without test cases may have edge-case bugs -- always test with real data
- Con:Different regex engines support different features, and the AI may default to the wrong flavor
Tips
- Be specific about what should and should not match -- include edge cases in your description
- Ask the AI to also provide test strings showing matches and non-matches
- Specify the regex flavor (JavaScript, Python, PCRE) if your environment matters