Regex String Generator
A validation rule is usually written as a regular expression, and then somebody has to invent twenty strings that satisfy it to test against. People write the same three shapes over and over and never produce the awkward ones the pattern also allows. This runs the pattern backwards instead — and then checks its own work with the real engine.
What this generator does
Parses the expression into a tree of literals, classes, groups, alternations and repeats, then walks it choosing among the options as it goes — and discards anything the real engine does not accept.
How to use this tool
- Type a regular expression, or press one of the examples.
- Choose how many strings you want.
- Add a seed if you need the same set again for a repeatable test.
- Copy the strings straight into a test or a fixture file.
Understanding the controls
- The pattern
- The regular expression, written as you would write it in code. Literals, character classes and ranges, the shorthands for digits, word characters and whitespace, the dot, groups, alternation, and the repeats *, +, ?, {n} and {n,m} are all understood.
- How many strings
- Up to fifty at once. Where the pattern has fewer distinct strings than that, you get all of them and no repeats.
- Seed (optional)
- Type anything to get the same strings again, which is what a repeatable test needs. Deterministic, not cryptographic.
Common use cases
- Building test data for a field with a validation rule
- Checking that a pattern really allows what you think it does
- Seeing the awkward shapes a pattern permits that you would not have written
- Producing sample reference numbers, codes or identifiers in a house format
- Teaching regular expressions by showing what a pattern generates rather than what it rejects
How this generator works
The expression is parsed into a tree and walked, choosing at random among the branches of an alternation and among the counts a repeat allows. A repeat with no upper bound has to stop somewhere, so it is capped at eight. Then comes the check that matters: every string is tested against the pattern anchored at both ends, using the browser's own regular expression engine rather than the parser that produced it — a generator that agrees only with itself proves nothing. The page also counts how many distinct strings the pattern can produce, where that is a finite number, so you can see when you have asked for more than exist.
Randomness and fairness
The choices come from your browser's cryptographic random source unless you give a seed, in which case the same seed gives the same strings — deterministic, not cryptographic.
For how randomness is produced across the whole site, see how Generate Random works.
Limitations and good to know
- Lookarounds, backreferences and word boundaries cannot be run backwards and are refused with a message saying so.
- An unbounded repeat is capped at eight, because otherwise there is no longest string.
- The dot produces printable characters rather than the whole of Unicode.
- Negated classes are drawn from the same printable set, so they do not produce control characters.
Privacy and your data
The pattern is parsed and the strings produced in your browser. Neither the pattern nor the results are transmitted or stored.
Related generators
- Regular Expression TesterRuns a pattern against your text, highlights every match with its position and groups, and refuses patterns that could hang the page.
- Regex Pattern Sample GeneratorA common validation regex paired with a real string it matches, for testing or learning pattern syntax.
- Synthetic Test Data GeneratorBuild a whole table of fictional records from the fields you choose, then export them as a table, JSON, CSV or SQL inserts.
- UUID GeneratorAn RFC 4122 v4 UUID for development or testing use — cryptographically random, not sequential.