Random Data from Regex
Generate random strings that match a regular expression.
Random Data from Regex
Turn a regular expression into random test data. Type a pattern such as [A-Z]{3}-\d{4} and the generator produces strings that match it – order numbers, licence keys, phone numbers, postcodes, usernames or any custom format your application validates. It is the reverse of a regex tester: instead of checking text against a pattern, it builds text from the pattern.
Pattern examples
| Pattern | Sample output |
|---|---|
[A-Z]{3}-\d{4} | QKR-0381 |
#[0-9a-f]{6} | #3fa91c |
+1 (\d{3}) \d{3}-\d{4} | +1 (415) 902-1177 |
[A-Z]{2}\d{2} ?\d[A-Z]{2} | SW11 4AB |
(\d)x\1 | 7x7 |
([A-Z0-9]{5}-){4}[A-Z0-9]{5} | 8K2PQ-…-ZT40M |
Alternation also works: (GET|POST|PUT) /api/v[12]/users picks one of the methods and one of the versions each time.
Why generate data from a regex?
- Validation testing – every generated value should pass your validator; if one fails, the pattern or the code is wrong.
- Fixtures and seeds – create IDs, SKUs and codes in exactly the format production uses.
- Fuzzing light – vary lengths and characters within the allowed format to catch edge cases.
- Documentation – show realistic examples of a format next to its regex.
How generation works
The pattern is parsed into a tree. For each string, alternatives are chosen at random, quantifiers pick a random repeat count, character classes pick a random member and backreferences copy the text their group produced. Slashes and flags around a pattern such as /abc/g are stripped. All randomness comes from your browser's secure generator and nothing is uploaded.
For random characters without a pattern, try the Random String Generator.
Frequently Asked Questions
Which regex features are supported?
Literals, escapes (\d \w \s and their negations, \n, \t, \xHH, \uHHHH), the dot, character classes with ranges and negation, groups, non-capturing and named groups, alternation with |, the quantifiers * + ? {n} {n,} {n,m} (lazy versions too) and backreferences like \1. Anchors ^ $ and word boundaries are accepted and ignored.
What is not supported?
Lookahead and lookbehind assertions and Unicode property escapes (\p{…}) are rejected with an error, because a generator cannot satisfy them reliably by construction. Rewrite the pattern without them.
Why are strings with * or + not very long?
Unbounded quantifiers would produce endless text, so they repeat at most the minimum plus the Extra repeats value (8 by default). Raise it for longer strings or use an explicit {n,m} range.
What do the dot and negated classes produce?
They draw from printable ASCII characters (space to ~), which keeps the output readable and safe to paste into forms and code.