Ad space (top)
Home β€Ί Prompt Library β€Ί Prompt for Writing a Regular Expression (Regex)

Prompt for Writing a Regular Expression (Regex)

Describe what you want to match and get a correct, explained regex you can trust.

Coding Β· Works great in Any AI

Copy-ready prompt

Write a regular expression that [matches/validates/extracts]: [describe in plain English].
Flavor: [JavaScript / Python / PCRE / etc].
Requirements:
- Provide the regex and explain each part.
- Give 3 matching and 3 non-matching examples.
- Note edge cases it does or doesn't handle.
- Keep it as readable as possible.

Want a version tailored to you?

Answer a few quick questions and the Code Prompt Generator builds a custom prompt from your exact details.

πŸ’» Open the Code Prompt Generator
Ad space (inline)

Why this prompt works

Regex is easy to get subtly wrong. This prompt returns the pattern with a part-by-part explanation and test cases, so you can verify it does exactly what you need instead of trusting an opaque string.

How to customize it

  • Specify the regex flavor; syntax differs across languages.
  • Test the provided examples before deploying it.
  • Ask for a simpler version if readability matters more than brevity.

Tip: replace the parts in [square brackets] with your own details before you send. The more specific you are β€” audience, tone, goal, constraints β€” the better the AI output.

Ad space (sidebar)