Promptabide Logo

Build and test a regex against your own match examples

Describe what to match, give examples that should and shouldn't match, and get a regex with a token breakdown, a pass/fail table and extra edge cases.

At a glance

Best for
Anyone writing a regex for validation or extraction who wants proof it handles their real examples, not just a plausible pattern.
Tested on
Claude · Opus 5.5
You fill in
goalflavormust_matchmust_not_match
You get
Ambiguities and assumptions Your examples always use grouping, so I'm treating ₹1234 (4+ digits, no commas) as not a match. Say if you want it… (full result below)

Prompt

Write a regular expression for: {{goal}}
Regex flavor: {{flavor}}

Must match (and what to capture, if anything):
{{must_match}}

Must NOT match:
{{must_not_match}}

Rules:
  • 1. Before writing it, list any ambiguity in my examples and the assumption you're making.

  • 1. Give the pattern, then a table: token | what it does.

  • 1. Test it against every example I gave, step by step, and show a pass/fail table. If anything fails, fix the pattern and test again before answering. Only show the final version.

  • 1. Add 3 edge cases I didn't think of and say whether each matches.

  • 1. Tell me if the pattern risks catastrophic backtracking, or if a parser would be a better tool than a regex for this job.
  • Fill in

    {{goal}}
    What the regex should match or extracte.g. Rupee amounts in free text, using Indian digit grouping
    {{flavor}}
    Regex engine or languagee.g. JavaScript (ES2018+)
    {{must_match}}
    Strings that must match, one per linee.g. ₹499, ₹1,23,456.50, Rs. 12,000
    {{must_not_match}}
    Strings that must not matche.g. ₹1,23,4567, ₹12,34, $1,299

    Example input

    goal: Find rupee amounts in free text (product descriptions, chat messages) that use Indian digit grouping, and capture the number part.
    flavor: JavaScript (ES2018+, lookbehind allowed)
    must_match:
    ₹499
    ₹1,299
    ₹1,23,456.50
    Rs. 12,000
    INR 2,50,000
    must_not_match:
    ₹1,23,4567
    ₹12,34
    ₹1,299.5
    $1,299
    1.1k0

    Generated Outputs (1)

    3 hours ago
    Claude
    Opus 5.5
    Generated Output
    Ambiguities and assumptions
  • • Your examples always use grouping, so I'm treating ₹1234 (4+ digits, no commas) as not a match. Say if you want it accepted.

  • • Decimals: exactly two digits, or none.

  • • Prefixes are case-sensitive (Rs, INR). Add the i flag if you want rs 500.

  • • A trailing sentence full stop (costs ₹499.) should still match.


  • Pattern
    `js
    /(?`

    | Token | Meaning |
    |---|---|
    | (? | not glued to a word (rejects XINR) |
    | (?:₹\|Rs\.?\|INR) | currency prefix |
    | \s? | optional space |
    | \d{1,2}(?:,\d{2})*,\d{3} | Indian grouping: 1–2 digits, any number of ,dd, then ,ddd |
    | \|\d{1,3} | or a plain amount under 1,000 |
    | (?:\.\d{2})? | optional paise |
    | (?![\d,]\|\.\d) | stop cleanly: no more digits, commas or decimal digits |

    Group 1 is the number without paise.

    Test results

    | Input | Expected | Result |
    |---|---|---|
    | ₹499 | match | pass, group 1 = 499 |
    | ₹1,299 | match | pass: 1,299 |
    | ₹1,23,456.50 | match | pass: 1,23,456 |
    | Rs. 12,000 | match | pass: 12,000 |
    | INR 2,50,000 | match | pass: 2,50,000 |
    | ₹1,23,4567 | no match | pass: 1,23,456 is followed by 7, so the lookahead fails and no shorter split works |
    | ₹12,34 | no match | pass: no ,ddd group, and 12 is followed by a comma |
    | ₹1,299.5 | no match | pass: .5 isn't two digits, and \.\d in the lookahead blocks stopping at 1,299 |
    | $1,299 | no match | pass: no prefix |

    Edge cases you didn't list
  • ₹1,234,567 (Western grouping): no match.

  • costs ₹499. at the end of a sentence: matches ₹499, because the full stop isn't followed by a digit.

  • ₹0.50: matches with group 1 = 0. Filter zero amounts in code if they matter.


  • Backtracking and alternatives
    There are no nested quantifiers over overlapping characters, so matching time stays linear. Regex is the right tool for finding amounts. To use them, strip commas and parse to integer paise in code. Never do arithmetic on the captured string.

    Why it works

    The must-not-match list matters as much as the positives. It's what forced the trailing lookahead that rejects ₹1,23,4567 instead of quietly matching its first part, the most common bug in AI-written regexes. "Test it step by step and fix before answering" makes the model check its own pattern instead of shipping a first draft. Stating assumptions up front surfaces choices (4-digit amounts without commas, case) you would otherwise discover in production. The backtracking warning protects you from patterns that hang on long inputs.

    When not to use it

    Don't rely on a regex alone for structured formats with checksums or grammar: emails you'll actually send to, URLs, HTML, JSON, tax IDs. Use a proper parser or validator library. The model's "test table" is reasoning, not execution, so paste the pattern into your test suite or a regex tester with the same examples before you trust it.
    Comments (0)
    No comments yet. Be the first to share your thoughts!
    Top Creators
    Follow PromptAbide

    New bides, prompt breakdowns and community picks, on whichever feed you already read.

    Trending Tags
    Loading...