gizmobench
BrowseDaily

Regex Generator

Generate a JavaScript regex from strings that should match, one per line. Mark strings that must not match with a minus sign and a space. The first positive example is split into runs of digits, letters, spaces and repeated punctuation. Runs that stay the same remain escaped literal text; differing runs use counted tokens bounded by the shortest and longest positive examples. You can choose each token, match the whole string or a substring, ignore case, or edit the pattern directly. Every example is scored, and a negative that still matches remains a visible conflict. This is a deterministic builder with 200-example, 500-character-per-example and 20,000-total-character limits; it does not use AI or infer a complete specification.

selectednothing yet
patternno flags

The pattern, what each piece of it means, and every example scored against it, appear here.

Positives
-
Negatives
-
Flags

Waiting for an example.

The runs of your first example

Each run of the first positive example gets a control here, once there is an example to cut up.

Match

A pattern built from examples is a guess at the rule behind them, not the rule itself, so it can match strings you never had in mind. Paste the ones that must not match as negative examples, with a minus sign and a space in front, and watch what the table says.

  • Three invoice numbersboth digit runs selected
    ^INV-\d{4}-\d{4}$
  • A literal dot, not selectedtext, not a wildcard
    escaped to \.
  • A negative that still matchesthe examples conflict
    named, never narrowed silently
Accuracy. The builder uses a fixed set of tokens and the lengths in your examples. Every example is tested with your browser's JavaScript engine and conflicts stay visible. A pattern can match strings outside your examples; manual edits are checked for repeat shapes that can backtrack heavily.

Common questions

How does it decide which parts to generalise?
By comparing your positive examples. The first one is the template: it is cut into runs of digits, letters, spaces and repeated punctuation, and every other positive example with the same run shape votes on each run. A run that reads the same in all of them stays literal text. A run that differs is generalised, and counted by the shortest and the longest your examples showed, so three four-digit years and one three-digit one give \d{3,4} rather than a guess. Nothing beyond that is inferred, and every run has a menu you can override.
Why did it escape the dot in my examples?
Because a dot in an example is a dot. An unescaped dot in a regular expression matches any character, so leaving it bare would quietly widen the pattern to strings you never showed it. Literal runs are escaped for every character that is special outside a character class, which is why a hyphen comes through as a hyphen while a dot comes through escaped. If you want that position to be a wildcard, choose Any character for that run and the escape goes.
A string I did not want still matches. What do I do?
Add it as a negative example: a line with a minus sign and a space in front of it. Every negative is run against the finished pattern too, and one that still matches is named as a conflict instead of being designed around. That conflict is the honest answer, because these tokens cannot tell those two strings apart. Narrow a run yourself, add a positive example that differs from the negative, or edit the pattern by hand.
Can I edit the pattern it gives me?
Yes. The pattern is an input, not a label: type in it and your examples are re-scored against what you typed, and Rebuild puts the built pattern back. One kind of edit is refused. A repeat with no upper bound wrapped around another repeat or an alternation, like (a+)+, and two unbounded repeats side by side, like \d*\d*, are the shapes that backtrack for a very long time on text that does not match, and a run like that cannot be interrupted once it starts. The page says so instead of running it. The regex tester runs a pattern like that in a worker it can stop.
Is this the regular expression my own code will run?
The output is tested with your browser's JavaScript RegExp engine, with no flags or i. Whole-string anchors or substring matching are selectable. This is not a Python, PCRE, RE2, .NET or application-specific generator: character classes, flags, anchors and escaping can behave differently in other engines, even when the syntax looks similar.
How many examples can I paste in?
Up to 200 examples, each up to 500 characters, and 20,000 characters in the box altogether. Past any of those the page names the limit you passed and the size that arrived, rather than building a pattern out of part of what you pasted. The first example is also cut into at most 60 runs, because a pattern with more pieces than that is longer than it is useful.
Does anything I paste leave the page?
No. There is no upload, no account and no request of any kind: the pattern is built and the examples are matched in this tab, by this page's own code. What you type is kept in your browser's local storage so the page opens where you left it, and the Start over button above the heading forgets it.
Is this an AI or natural-language regex generator?
No. It builds from positive string examples using a fixed token set and their observed run lengths. Describe your rule through examples and check the negatives; arbitrary prose, unseen constraints and a complete validation grammar are not inferred.
Can it generate strings from a regex or an exact numeric range?
No. This workflow goes from examples to a pattern. Random strings from a pattern, finite automata, exact numeric-range generation and production password, email or URL validation require different rules. Samples alone do not establish those rules.

The builder uses a fixed set of tokens and the lengths in your examples. Every example is tested with your browser's JavaScript engine and conflicts stay visible. A pattern can match strings outside your examples; manual edits are checked for repeat shapes that can backtrack heavily.