BestPromptFinder
Home › Coding › Write and Explain a Regex With Test Cases

Write and Explain a Regex With Test Cases

Coding · ChatGPT, Claude, Gemini · data
85AI Quality /100
91AI Usefulness est. /100
76Eval Confidence /100
No votes yetCommunity results

Quality, usefulness and confidence are AI evaluations out of 100 — not user ratings. Community results come from visitors' "worked / didn't work" votes below. How scoring works →

The prompt

Write a regular expression for me and prove it works. What it should match: [e.g. Indian mobile numbers with or without +91 / PAN format / dates like 17-10-2026 / email addresses in a log line] What it must NOT match: [examples] Where I'll use it: [Python / JavaScript / Java / grep / a form validator / Excel or Google Sheets] Whole-string match or find inside text: [ ] Give me: 1. The regex, written for my language's flavour. 2. A piece-by-piece explanation in a table: part | meaning. 3. Ten test strings: six that should match and four that shouldn't, including tricky edge cases, with the expected result for each. 4. A tiny code snippet that runs those tests in my language. 5. Limits: what the pattern deliberately doesn't check (e.g. it validates format, not whether the number exists). Rules: prefer a readable pattern over a clever one; avoid patterns that can backtrack badly on long input; if my examples conflict, point that out first.
Find similar in the app →
Did this prompt work for you?

Why this prompt

Source

Created by BestPromptFinder — editorial prompt, not user-generated. See our content & source policy.

Related Coding prompts

Python: Download a CSV From a URL
Quality 94 · GPT-5.6
Public-Market and Competitor Data Collection Agent
Quality 92 · GPT-5.6
Plain-English to SQL Query Writer
Quality 91 · GPT-5.6
PRD to MVP Technical Plan
Quality 90 · Claude Code
Third-Party API Integration
Quality 90 · Claude Code
Database Schema and Migration
Quality 90 · Claude Code