ToolLineup

Random Data from a Regex

Give a regular expression and get strings that match it — order IDs, SKU codes, licence keys, postcodes, anything with a known shape. Character classes, ranges, alternation, groups and quantifiers are all honoured. Constructs that describe context rather than characters, such as lookahead and backreferences, cannot be generated from and are reported rather than silently ignored. Every batch is checked back against the real regular expression engine. Everything is generated in your browser; nothing is uploaded and no result is recorded anywhere.

How it works

This runs a regular expression backwards: instead of testing whether a string matches, it builds strings that do. Character classes, ranges, alternation, groups and quantifiers are all honoured, and an unbounded quantifier such as*is given a small random repeat count so the output stays a usable length.

Some of the regex language describes context rather than characters. A lookahead, a lookbehind or a backreference constrains what may surround a match, and there is nothing in it to generate from — those are reported below rather than being silently dropped, because ignoring one produces output that does not match the pattern you typed.

Every batch is checked back against the real regular expression engine, so a mismatch is caught rather than shipped.

Start from an example
Generated values20
  • ORD-11905
  • ORD-51403
  • ORD-22589
  • ORD-15365
  • ORD-33431
  • ORD-10430
  • ORD-99677
  • ORD-51575
  • ORD-38842
  • ORD-94517
  • ORD-17500
  • ORD-04918
  • ORD-70050
  • ORD-27669
  • ORD-73332
  • ORD-10183
  • ORD-03627
  • ORD-82473
  • ORD-49076
  • ORD-95098

Frequently asked questions

Why can lookahead and backreferences not be generated from?

They constrain a match against its surroundings rather than describing characters. A lookahead says what must follow, and a backreference says a later part must equal an earlier one — neither adds anything to build from, so they are reported instead of being quietly dropped.

How are unbounded quantifiers handled?

A star or plus has no upper limit, so a random repeat count in a small range is used. That keeps the output a usable length instead of occasionally producing something enormous.

Is the output guaranteed to match the pattern?

Every batch is tested against the real regular expression engine, and any mismatch is reported. That check is what catches the cases where a pattern uses a construct the generator cannot fully honour.

Why did "no duplicates" give me fewer values than I asked for?

Some patterns describe only a handful of strings — a pattern like (yes|no) has exactly two. When the pattern cannot express as many distinct values as you asked for, the shortfall is reported rather than the tool looping.

Can I use this to generate realistic test data?

For anything with a fixed shape, yes: reference numbers, product codes, postcodes, version strings. For names, addresses and emails that need to look plausible rather than merely well-shaped, the sample data generator is the better fit.

Related tools