Regex prompt
A copy-and-paste prompt for ChatGPT, Claude or Gemini that gets a professional regex on the first try, plus the cheapest model that does it well.
What most people type
regex for US phone numbers
It works, but the AI has to guess your language or regex flavor and whole string or find within text, so the first answer usually needs another round. The version below asks for exactly what a professional would deliver.
The better prompt
Write a regex that matches US phone numbers. Accept common formats such as 5551234567, 555-123-4567, (555) 123-4567, 555.123.4567 and +1 555 123 4567. Regex flavor: [language or regex flavor]. Match against: [whole string or find within text]. Give the regex in a code block, then 1-2 lines explaining how it works and what it won't match. Add a few example strings that match and a few that don't.
Replace the [brackets] with your details before you send it: language or regex flavor, whole string or find within text.
What a professional regex prompt covers
- Formats to accept placeholder or common formats
- Language or engine placeholder
- Test examples
Best AI model for this prompt
This is a everyday task. You don't need the most expensive model. The cheapest model at each company that handles it well:
| Company | Model | Per use | Per 1,000 uses |
|---|---|---|---|
| Anthropic | Claude Sonnet 5.5 | $0.0042 | $4.22 |
| OpenAI | GPT-6.1 Terra | $0.0021 | $2.11 |
| Gemini 3.8 Flashcheapest | $0.0016 | $1.58 |
Pay-per-use list prices for this prompt and its expected answer (about 400 tokens). On a monthly chat plan, the same choice shows up as more messages before you hit your limit. See today's AI prices.