Turn a regular expression into test data
Normally a regular expression checks whether text matches a pattern. This tool works the other way round: it reads the pattern and produces random data from regex rules, so every generated string matches. That makes it a quick way to create realistic identifiers for unit tests, form validation checks and database fixtures without writing a custom generator.
Examples of random data from regex patterns
| Pattern | Sample output |
|---|---|
[A-Z]{3}-\d{4}-[a-z0-9]{6} | KQD-4821-x7m2pa |
INV-20(2[4-6])-\d{5} | INV-2025-03917 |
(red|green|blue)-(small|large) | green-large |
\d{3}-\d{3}-\d{4} | 415-208-7731 |
[a-z]{5,10}@example\.com | qhtwbzm@example.com |
Patterns for everyday test values
A loose pattern produces values that match but would never occur in real data. These patterns are tight enough to look realistic:
| Value | Pattern |
|---|---|
| Hex colour | #[0-9a-f]{6} |
| Semantic version | [1-9]\.\d{1,2}\.\d{1,2} |
| US ZIP+4 code | \d{5}-\d{4} |
| IPv4 address, valid octets only | ((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d) |
| ISO date in 2025 | 2025-(0[1-9]|1[0-2])-(0[1-9]|1\d|2[0-8]) |
The IPv4 row shows the trade-off: the short pattern (\d{1,3}\.){3}\d{1,3} also produces addresses such as 999.12.0.456, which a correct validator must reject. That makes it a handy source of invalid cases, while the long version gives valid ones. The date pattern stops at day 28 so every generated date exists.
Supported syntax
- Literal characters and escaped metacharacters such as
\.and\-. - Character classes
[abc], ranges[a-f0-9]and negated classes[^0-9]. - Shorthand classes
\d,\w,\sand their negations\D,\W,\S. - Quantifiers
?,*,+,{n},{n,}and{n,m}, including lazy forms. - Groups, non-capturing groups
(?:…), named groups, alternation with|and back-references like\1. - Escapes such as
\t,\x41and\u00e9.
Anchors (^, $, \b) are accepted but produce no characters, and lookahead or lookbehind groups are skipped because they do not describe characters to output. The dot . produces any printable ASCII character.
The maximum repeat setting
Quantifiers like *, + and {2,} have no upper limit, but a generator must stop somewhere. The maximum repeat value (1–50, default 10) caps how many extra repetitions those open-ended quantifiers can add. Lower it for short, readable output; raise it to test length handling.
Common pitfalls
- Unescaped dots. In
example.comthe dot matches any character, so you may getexample#com. Writeexample\.cominstead. - Negated classes are wide.
[^a-z]can produce spaces and punctuation from the whole printable ASCII range. Prefer a positive class that lists what you want. - Unicode ranges. Ranges larger than about 5,000 code points are rejected to keep generation fast; split them into smaller ranges if you need accented or non-Latin characters.
Tips for good test data
- Write the tightest pattern you can.
\w+yields gibberish;[A-Z][a-z]{3,8}looks like a name. - Use the same pattern your validation code uses to prove that valid input is accepted, then modify it slightly to generate invalid cases.
- For structured records (names, emails, cities) the random JSON generator produces more realistic values, and for simple tokens the random string generator is faster.
Output is generated with a secure random source in your browser; patterns and results are not sent anywhere.