
- Updated
Write a regex from a plain description
This prompt writes a regex from a plain description. You give the language or tool, examples that must match and examples that must not, and what you are trying to do. Test it on your own data.
Write a regular expression. Language or tool: [e.g. JavaScript, Python, grep] It must match: [EXAMPLES THAT SHOULD MATCH] It must not match: [EXAMPLES THAT SHOULD NOT] Task: [FIND / VALIDATE / REPLACE] Give the regex, a part-by-part explanation, a test table of my examples with expected results and any edge cases to watch out for.
Always test with your real data. Regex answers from AI can be subtly wrong.
Get a better result
A regular expression for your language or tool, explained piece by piece, with a test table showing your matching and non matching examples and their expected results, plus edge cases to watch.
Examples beat descriptions for regex, so the prompt asks for strings that must match and strings that must not. The part by part explanation lets you maintain it later. The test table turns your examples into a check, and the edge cases list points at the inputs most likely to slip past.
The regex matches part of a longer word.
Fix: Ask for word boundaries or start and end anchors where the whole value must match.
- It works in one tool but not in yours. Name the exact tool, as the prompt asks, since features like lookbehind differ between them.
- The test table says it passes but it does not. Run it on your real data, as the tip says, in your code or a regex tester, before you trust the table.
Ask whether a few lines of normal code would be clearer than the regex for this task, and show both.
This input should not match but it does: [EXAMPLE]. Fix the regex and add it to the test table.
More chat & writing prompts
See all 465 →More like this
- Create TypeScript types from a JSON responseClaude · ChatGPT · Gemini
- Clean a messy spreadsheet with PythonClaude · ChatGPT · Gemini
- Build a React component from a descriptionClaude · ChatGPT · Gemini
- Write the tests first for a new featureClaude · ChatGPT · Claude Code
- Write a technical specChatGPT · Gemini · Claude



