Regex from examples
Turn sample strings into a regular expression, and see which examples it matches.
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.