Skip to content
100% local

Regex from examples

Turn sample strings into a regular expression, and see which examples it matches.

Input
Examples the pattern should NOT match
Output

Regex from examples

Paste a handful of strings the pattern should match — one per line — and this tool infers a regular expression that captures the shape they share. Underneath the generated pattern it lists each example with a checkmark, so you can see at a glance whether the result actually covers what you pasted.

The generalization level controls how literal the result is. "Exact characters" keeps every character as-is and only combines differently shaped examples with alternation. "Character classes" replaces digits, letters and spaces with \d, \p{Lu}/\p{Ll} and \s while keeping the exact repeat counts from your examples. "Flexible quantifiers" goes further and turns those runs into one-or-more matches, which generalizes better but also matches more than your samples. Anchoring adds ^ and $ so the whole string has to match rather than just a substring, case sensitivity controls whether letter case matters, and named groups wrap the variable parts of the pattern so you can pull them out by name later. The dialect option adjusts how named groups are written for JavaScript, PCRE or Python, since the three don't agree on that syntax.

Add strings the pattern must NOT match in the second field, and the tool checks the generated pattern against them too — any negative example it still matches gets flagged, which is the fastest way to catch a pattern that's too broad. Turn on the explanation to get the pattern broken into its individual pieces with a plain-language description of what each one does.

Everything runs locally in your browser: the examples you paste, the negative examples, and the generated pattern never leave your device. Copy the result, download it as a .txt file, or send the output back into the input to refine it against more examples.

FAQ

Does the generated regex always match every example I pasted?
Yes — the pattern is built directly from your examples, so it is designed to match all of them under the strictness level you chose. If your examples have genuinely different shapes, the tool falls back to matching any of the distinct forms.
What does "character classes" actually change?
It replaces runs of digits, letters and spaces with their regex class (\d, \p{Lu}, \p{Ll}, \s) instead of the literal characters, while keeping the exact length seen in your examples — so "AB12" becomes \p{Lu}{2}\d{2}, not a literal "AB12".
Why did the pattern also match one of my negative examples?
A negative match usually means the generalization is broader than your intent — try a stricter level, turn on anchoring, or add a more specific negative example so the flagged line shows exactly what slipped through.
Will the pattern work exactly the same in Python or PCRE?
The character classes and quantifiers are shared across dialects, but named-group syntax differs — the dialect option only adjusts how those groups are displayed (JavaScript uses (?<name>…), PCRE and Python traditionally use (?P<name>…)); always test the result against your actual engine.
Are my example strings uploaded anywhere?
No. The pattern is generated entirely in your browser — your examples and the generated regex never leave your device.