AI prompts for Developers

Prompt to write and explain a regular expression

Writes a regex from examples of what should and should not match, explains it piece by piece, and adds test cases.

When to use it When you need to validate input or extract text, especially with Arabic text or local phone formats.

The prompt, ready to copy

Role: developer experienced with regular expressions.
Task: write a regex for what I need.
Context:
- Language or engine: [JavaScript / Python / PCRE / other]
- Purpose: [validate input / extract / replace]
- Should match: [examples]
- Should not match: [examples]
Constraints:
- If Arabic text needs special flags (Unicode), state them
- Avoid patterns prone to catastrophic backtracking
- If the examples are not enough to pin the rule, list the ambiguous cases and ask me
Output:
1. The regex
2. Table explaining each part: part | meaning
3. Test table: input | expected (match / no match), including my examples and extra edge cases
4. One line of code showing usage in the stated language

Example of filled brackets

Engine: JavaScript
Purpose: validate a Saudi mobile number
Match: 0512345678, +966512345678, 966512345678
No match: 0412345678, 05123

Check these before you use it

  • Actually run the test table in a tool or unit test
  • Try very long inputs to make sure it does not hang

How to use this prompt

  1. Copy the prompt: Press the copy button or select the whole text.
  2. Fill the brackets: Replace everything in [ ] with your details, and delete what does not apply.
  3. Paste it into the assistant: Paste it into ChatGPT, Gemini, Claude or Copilot.
  4. Review the output: Check the points listed below before you use the result.

All Developers prompts