Regex String Generator (Reverse Regex)
A regular expression describes a set of strings. This tool works backwards from the pattern to that set, generating concrete examples that match — so you can sanity-check a validation rule, build test fixtures, or simply understand what a dense pattern really accepts. It handles the common building blocks: character classes, \d \w \s, quantifiers, groups, and alternation.
How to use the Regex String Generator (Reverse Regex)
Type a regular expression without the surrounding slashes or flags — for example [A-Z]{3}-\d{4} for a license-plate style code. Choose how many examples you want and click Generate. Each line in the output is an independent string that the pattern matches.
Unbounded quantifiers are sampled with a sensible cap so output stays readable: * expands to between zero and three repetitions, + to between one and four, and {n,} to between n and n+3. Bounded quantifiers like {2,5} are respected exactly. Alternation picks a random branch each time, so generating a batch shows the variety a pattern allows.
If the pattern uses a feature the generator does not model — lookahead, lookbehind, or backreferences — it will tell you in the note below the output rather than produce a misleading result.
How reverse-regex generation works
A regex can be read as a small grammar. The generator parses your pattern into a tree of nodes — literals, character classes, escapes, groups, alternations, and quantifiers — then walks that tree producing one random valid choice at each step. A character class such as [a-f0-9] becomes "pick one character from this set"; a quantifier such as {2,4} becomes "repeat the preceding node a random number of times in that range"; an alternation cat|dog becomes "choose one branch."
This is the inverse of matching. A matcher answers "does this string belong to the set the pattern describes?" A generator samples members of that set directly. Because most patterns describe an infinite set (any + or * allows unbounded length), the generator can only ever show a finite sample, and it deliberately keeps repetition counts small so the examples are legible.
The supported subset covers the vast majority of validation patterns developers write day to day: anchors, literals, the predefined classes \d \w \s and their negations, custom classes with ranges and negation, the dot, non-capturing and capturing groups, alternation, and all standard quantifiers. Assertions and backreferences require tracking already-generated text, which is outside this lightweight model.
Common use cases
- Test fixtures. Generate a dozen strings that pass a validation regex to feed into unit tests, without hand-writing each one.
- Understanding a pattern. When you inherit a cryptic regex, seeing real matching strings is faster than parsing the syntax in your head.
- Sample data. Produce realistic-looking identifiers, SKUs, or codes that follow a known format.
- Spotting over-permissive rules. If the generated examples include strings you did not expect to be valid, your pattern is too loose.