Skip to main content
KX Toolkit

Regex from Examples

Paste lines that should match and lines that should not - get a regex that satisfies both.

Developer Tools

Paste lines that should match and lines that should not - get a regex that satisfies both.

This free Regex from Examples from KX Toolkit is part of our all-in-one online toolkit. It runs entirely in your browser, so your data never leaves your device for client-side operations. 100% free, forever - no paywall, no credit card, no trial.

How to use the Regex from Examples

  1. Paste your input - JSON, regex pattern, JWT, URL etc.
  2. Pick any flags or options the tool supports.
  3. Click the action button (Format, Test, Decode).
  4. Copy the result or download it as a file.

What you can do with the Regex from Examples

  • Format and validate API responses while debugging.
  • Test regex patterns against real input before deploying.
  • Decode JWTs to inspect claims and expiry.
  • Generate UUIDs for migrations, tests and seeders.

Why use KX Toolkit's Regex from Examples

  • Browser-based: Works on Windows, macOS, Linux, iOS and Android - no install, no extension.
  • Privacy-first: Client-side tools never upload your data; server-side tools delete files right after processing.
  • Mobile-friendly: Full feature parity on phones and tablets - not a stripped-down view.
  • Fast: Optimised for instant feedback. No artificial waiting screens, no email-gated downloads.
  • One hub for everything: 300+ tools across SEO, text, image, PDF, code, color, calculators and more - skip switching between sites.

Tips for the best results

Bookmark the most-used tools - your browser bookmark bar is faster than retyping the URL every time.

Related Developer Tools

If you find this tool useful, explore the full Developer Tools collection or browse our complete tool directory. KX Toolkit is built for marketers, developers, designers, students and anyone who needs a quick utility without signing up for yet another SaaS.

How does it generate a regex from examples?
It looks for the longest substring shared by all positive examples, splits each line into a shared prefix, that common middle, and a shared suffix, then characterises whatever varies - digits become \d, letters become [a-zA-Z], mixed runs become a wider character class. It then verifies the candidate against your negatives and falls back to looser or tighter alternatives until both lists are satisfied or 1000 attempts have been tried.
How many examples should I provide?
Three or more positive examples that share structure work best, because the tool needs at least two strings to extract a meaningful common substring, and a third helps it tell whether varying parts are digits, letters, or mixed. Negatives are optional but very useful - they prevent the tool from generating an over-broad pattern that matches things you do not want.
Will the regex always be perfect?
No. The output is a best effort. If your positives have nothing in common (for example, "cat", "1234", "@#$") the tool falls back to an alternation listing each example literally. If a negative happens to share structure with a positive, no regex can satisfy both - the tool will pick the closest miss and the verification badges will show which line is wrong.
Where does it run?
Entirely in your browser. The pattern generation, the verification, and the live badges all use plain JavaScript. Nothing is uploaded, no servers are contacted. Even the regex compilation uses the browser built-in RegExp engine, so the dialect is exactly what you would use in JavaScript code - note that lookbehind and named groups have wide modern support but may not work on older browsers.
How do I read the verification badges?
Each line gets a colour-coded row: green with a checkmark means the regex behaved as expected for that line (a positive matched, or a negative was excluded). Red with a cross means the opposite - a positive that was missed or a negative that snuck through. Aim for all green; any red indicates the generated pattern needs help, usually by adding more contrasting examples.
Can I edit the generated regex?
Not in place - the output box is read-only. The tool is meant to give you a starting point you copy into your code or paste into a regex tester to refine. If the generated pattern is close but slightly off, copy it, tweak it manually, and re-run it against the originals to check. For interactive editing of regex, use the dedicated Regex Tester tool.

No reviews yet

Be the first to share your experience with the Regex from Examples.