FormatterHQ

Generate Random Data from a Regex

Type a regular expression and get random strings that match it, such as order numbers, licence-plate style codes or product SKUs for your test data.

Output TEXT
Ready.

How to use the Random Data from Regex

  1. Enter a regular expression, for example [A-Z]{3}-\d{4}.
  2. Choose how many strings to generate.
  3. Set the maximum repeat used for open-ended quantifiers such as * and +.
  4. Generate and copy the matching strings into your tests or fixtures.

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

PatternSample 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\.comqhtwbzm@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:

ValuePattern
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 20252025-(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, \s and 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, \x41 and \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.com the dot matches any character, so you may get example#com. Write example\.com instead.
  • 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.

Frequently asked questions

Does every generated string really match the pattern?
Yes for the supported syntax. Anchors are ignored and lookaround assertions are skipped, so patterns that depend on lookahead to exclude values may produce strings the full regex would reject.
Why do I get an "unsupported group type" error?
Some engine-specific constructs, such as conditionals or inline flags like (?i), are not supported. Rewrite the pattern using plain groups and character classes, for example [Aa] instead of a case-insensitive flag.
Can I paste a pattern with slashes like /abc/g?
Yes. Leading and trailing slashes and any flags after them are removed before the pattern is parsed.
How can I limit the length of .* in my pattern?
Lower the maximum repeat setting, or replace the open quantifier with an explicit range such as .{0,5}.

Last updated September 26, 2026

Guides

Related tools

Regex Cheat Sheet Interactive regex cheat sheet: anchors, classes, quantifiers, groups, lookarounds, flags and Unicode, with clickable examples and a flavour table. Regex Escape Escape special characters so any text can be matched literally inside a regular expression in JavaScript, PCRE, Python or Java. Regex Explainer Break a regular expression into tokens and explain each part in plain English: groups, quantifiers, classes, anchors and lookarounds. Regex Patterns Library Copy-ready regex patterns for email, phone, URL, IP, dates, numbers, UUIDs, postal codes and passwords, each with examples and a live test box. Regex Tester Test JavaScript regular expressions live: highlight matches, inspect capture groups and named groups, try flags and preview replacements. Random Alphanumeric Generator Generate letters-and-digits codes for vouchers, reference IDs and usernames in mixed, upper or lower case. Random Date Generator Generate random dates or date-times between two dates in ISO, US, EU, long, Unix or RFC formats. Random Decimal Generator Generate random decimal (floating-point) numbers in a range with a fixed number of decimal places. Random Emoji Generator Generate random emoji from smileys, animals, food, travel, objects or symbols to copy and paste. Random Fraction Generator Generate random proper fractions such as 3/7 with a maximum denominator, simplified automatically. Random Hex Generator Generate random hexadecimal numbers and strings of any length, in upper or lower case. Random Integer Generator Generate uniform random integers between inclusive bounds, with negatives, unique draws, sorting and up to 10,000 values.