Goal
Write a regular expression that matches exactly what is described and nothing more, then prove it with tests.
Inputs
- What to match: [e.g. Indian mobile numbers with optional +91, or order IDs like ORD-2026-00451]
- Purpose: [validate a full field, find inside text, extract a group, search and replace]
- Regex flavour: [JavaScript, Python, PCRE, Java, .NET, Google Sheets RE2]
- Examples that should match: [paste examples]
- Examples that should not match: [paste examples, or leave blank]
Output format
- The pattern on its own line, with any flags named separately.
- Explanation table:
| Part | Meaning |
- Test table with at least eight should-match and eight should-not-match strings:
| String | Should match | Does match | Captured group, if any |
- Usage line: one line showing how to apply the pattern in the stated language.
- Limits: cases the pattern deliberately does not handle.
Check before answering
- Anchors are used for full-field validation and omitted for search inside text.
- The pattern uses only features supported by the stated flavour; for example, no lookbehind where it is unsupported.
- No nested quantifiers that could cause catastrophic backtracking.
- Special characters are escaped correctly.
- Every row in the test table is evaluated correctly against the final pattern.
- Groups are non-capturing unless the value needs extracting.
- The pattern is as simple as the requirement allows.






