Regex Data Generator

Run a regular expression backwards and get a list of strings that the pattern would accept.

Regular expression
Matching strings
Runs locally in your browser

About the Regex Data Generator

A regular expression normally answers yes or no about a string you already have. This tool runs the pattern the other way: it reads the expression, walks the syntax tree and emits strings the pattern would match, which is the quickest way to produce invoice numbers, licence keys, order codes or phone numbers in exactly the format your validator expects.

The supported syntax covers literals, escapes such as \d, \w, \s and their negated forms, character classes with ranges and negation, the dot, groups and non capturing groups, named groups, alternation with |, back references like \1, and the quantifiers *, +, ?, {n}, {n,} and {n,m}. Slash delimiters and trailing flags are stripped, so pasting /^[a-f0-9]{8}$/i works. Anchors are treated as zero width and produce nothing, exactly as they do when matching.

Open ended quantifiers have no upper bound, so the Repeat limit decides how far *, + and {n,} expand: a limit of 5 turns a+ into one to six letters. Lookaheads and lookbehinds are rejected with a message, because a condition about surrounding text cannot be replayed forwards. Patterns with few possibilities, such as [ab], run out of unique values and the status line says so. To check the strings afterwards, paste them into the regex tester, or read the pattern in plain English with the regex explainer.

How to use

  1. Paste a regular expression, with or without the surrounding slashes.
  2. Set How many strings you need and the repeat limit for open quantifiers.
  3. Leave Unique results ticked to skip duplicates.
  4. Copy the list, or run it again for a different draw.

Common questions

Which regex features are not supported?
Lookahead, lookbehind and conditional groups are rejected, since they describe context that cannot be generated forwards.
Why did I get fewer strings than I asked for?
With Unique results on, a narrow pattern such as [ab]{2} has only four possible values and the tool stops once it has them all.
What does the repeat limit do?
It caps unbounded quantifiers. With a limit of 5, a+ produces between one and six characters instead of an arbitrary length.
Can I paste a pattern with flags?
Yes. A pattern written as /pattern/gi has its slashes and flags removed before parsing; the flags do not change what is generated.