BrowserDevTools

Regex generator from examples

Paste the text, then the parts you want to match (one per line). You get ranked candidates, an explanation of every piece, a live highlight test against your own text, and the exact code to paste into JavaScript, Python, PCRE or RE2.

Flags

The text and the expectations are processed in this tab. Nothing is uploaded and no share link is created.

Candidates

How this pattern was built

  • IDliteral “ID”
  • -literal “-”
  • \d+digit run “4821” → \d+

Paste into

g
/ID-\d+/g

Test on your text

2 hits · 2 expected
# Deploy log
[12:04:11] build ID-4821 started
[12:04:18] artifact app.tar.gz ready
[12:04:23] report mailed to ops@example.com
[12:05:02] build ID-4824 started
[12:05:19] smoke tests passed

Not matched by this candidate

  • # Deploy log [12:04:11] build
  • started [12:04:18] artifact app.tar.gz ready [12:04:23] repo
  • started [12:05:19] smoke tests passed

The candidates describe the shape of your examples, not their meaning — read the hit counts and try a second example before trusting one.

Why “from examples” is a different tool

Search for a regex generator and the first page is explainers, cheat sheets and “human-readable” translators. Those assume you already know what pattern you want and just need it written out. The harder moment is earlier: you have a pile of strings that should match — log IDs, ticket references, a column out of a spreadsheet — and you want the pattern, not a lecture.

That moment has a trap, and this tool is built around avoiding it: a pattern that looks plausible often matches things you never intended. So every candidate here is run back over your own text before it is offered, and the ranking says which ones reproduced your examples exactly and which ones went too far:

Everything is computed in your browser: nothing is uploaded and there is no share link. The candidates use only constructs shared by JavaScript, Python, PCRE and RE2 — no backreferences and no lookaround — so the same pattern behaves the same way wherever you paste it, and the tool refuses to hide a catastrophic-backtracking risk if you edit one in yourself. Treat the output as a starting point for review, not as a spec: it induces the shape of your examples, never their meaning.

FAQ

Is my text uploaded?
No. Occurrence finding, generalisation and the verification run all happen in your browser tab. There is no backend endpoint for the text, no logging and no share link — you can confirm it in the Network panel.
What does it actually infer?
Form, not meaning. Give it john@example.com and it can offer the email shape, because that shape is in the library. Give it SKU-99123 and the honest answer is “letters, a dash, then digits” — which is a real improvement over hand-writing \w+-\d+, but it is not a claim about what a SKU is. The test panel exists so you can judge the result instead of trusting it.
What if a candidate matches more than my examples?
It says so. The badge shows the extra hit count, that candidate is ranked below the ones that reproduced your examples exactly, and the unmatched-segments list shows what the pattern skipped. If nothing reproduces your examples exactly — for instance when two examples overlap — the tool tells you that instead of presenting a wrong pattern as a success.
Are the generated patterns safe to run?
The candidates contain no backreferences, no lookaround and no nested quantifiers, which keeps them RE2-compatible and avoids catastrophic backtracking. If you edit one and nest a quantifier inside a quantified group, the tool flags it. That said, a pattern is only as good as its verification: test it against real data before it guards anything.
Which flavours are supported?
JavaScript, Python, PCRE/PHP and RE2. Only shared constructs are emitted, so the same pattern means the same thing in all four; the export block rewrites it into the idiomatic form for the flavour you pick (a regex literal, re.compile, or an RE2::PartialMatch call).