Coding prompts · Prompt
Write a regex (prompt)
write-regex-prompt
A prompt that writes a regular expression from a plain-English description for your language, then explains it piece by piece and tests it against strings that should and should not match, flagging slow or risky patterns. Use when the user needs a regex, asks to match emails, phone numbers or URLs, or a regex is not matching.
Works with: Any AI Not yet model-tested; testing Jan 2027
Paste it into ChatGPT, Claude, Gemini or any AI chat, then tell it about your project. How it works
Install in Claude Code, Cursor or Codex (optional)
Only for AI coding tools that read skill folders. Run one line in a terminal, in your project folder. It downloads this skill's text files from TheSkillVault and nothing else; you can read them first with “View raw SKILL.md”.
Claude Code (all your projects)
curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/write-regex-prompt/raw' -o ~/'.claude/skills/write-regex-prompt/SKILL.md'Cursor (this project)
curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/write-regex-prompt/raw' -o '.cursor/skills/write-regex-prompt/SKILL.md'Codex and other Agent Skills tools (this project)
curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/write-regex-prompt/raw' -o '.agents/skills/write-regex-prompt/SKILL.md'
Or connect the whole library over MCP
Add TheSkillVault to Cursor or add this to your app's MCP settings (read-only; help):
{
"mcpServers": {
"theskillvault": {
"url": "https://theskillvault.ai/mcp"
}
}
}Regexes are easy to get almost right. This prompt writes one, explains it and tests it on both kinds of input.
When to use
- You need to validate, find or extract text: emails, phone numbers, dates, IDs.
- A regex you found online does not match what you expect.
- You want to understand a regex before trusting it.
Steps
- Describe what should match, in plain English, with a few real examples.
- Add examples that must not match. These catch most mistakes.
- Fill in {{LANGUAGE}} (JavaScript, Python, PCRE, Go and so on) and paste the prompt.
- Run its tests in your code or on regex101.com before shipping.
Prompt
Write a regular expression for {{LANGUAGE}}.
What it should match: {{DESCRIPTION}}
Examples that must match: {{MATCH EXAMPLES}}
Examples that must not match: {{NON-MATCH EXAMPLES}}
Use: {{validate a whole field / find inside longer text / extract parts}}
Give me:
1. The regex, ready to paste, with the flags it needs.
2. A token-by-token explanation in a short table.
3. A test table: every example above plus 3-5 tricky ones you add, with match yes/no and any captured groups.
4. Risks: catastrophic backtracking (nested quantifiers), missing anchors, or cases it cannot handle. If a regex is the wrong tool (for example full email or HTML parsing), say so and suggest a better approach.
5. A one-line code snippet showing how to use it in {{LANGUAGE}}.
How to adapt
- Fixing an existing regex? Replace the description with the regex and say what it gets wrong.
- Need it readable for a team? Ask for a verbose or commented version.
Gotchas
- Regex flavours differ: lookbehind, named groups and Unicode classes vary by language. Always name yours.
- Badly built regexes can freeze a server on long input (ReDoS). Never run user-supplied patterns, and test on long strings.
- Do not paste real customer emails or phone numbers as examples; make up similar ones.
Portability
Works with any language and any chat AI. Test on regex101.com or in your own test runner; no tool lock-in.
Done when
- The regex passes every must-match and must-not-match example.
- You understand each part from the explanation table.
Example prompt
"Write a JavaScript regex that matches Australian mobile numbers like 0412 345 678 or +61412345678, but not landlines."
---
Based on the "RegEx Generator" prompt by ersinyilmaz on prompts.chat (CC0 1.0, public domain).
Licence
Adapted from ersinyilmaz (prompts.chat, 'RegEx Generator') (Public domain (CC0 1.0) - prompt contributed to prompts.chat by ersinyilmaz), CC0 1.0. Adapted by TheSkillVault: replaced pattern-only output with flavour selection, a token-by-token explanation, must-match and must-not-match tests and a backtracking check; added steps, adapt notes and done-when.
Licence: CC0 1.0. Attribution when you reuse it: Based on work by ersinyilmaz (prompts.chat, 'RegEx Generator') (Public domain (CC0 1.0) - prompt contributed to prompts.chat by ersinyilmaz, CC0 1.0), https://github.com/f/prompts.chat/blob/b09880e229d2f091ffa2254bc187532fb8980f9b/prompts.csv; adapted by TheSkillVault, https://theskillvault.ai