Skip to content
faker.tools
All 79

Plate IV · Developer, API & Database Seeding Utilities

Regex Data Generator

Random strings that match your regular expression, each one verified against it.

#ValueMatches
1XS-2472-h9dm21true
2VU-3902-srufaltrue
3GY-9711-b0eez5true
4GB-1853-k7bh7ltrue
5OH-3756-hcvkxstrue
6QB-2843-8b38qptrue
7IG-2102-wd559gtrue
8PS-3386-igoncntrue
9FO-9971-6y6g6dtrue
10YM-6053-wb8qq1true
10 rows · 329 BGenerated in your browser · Regex Data Generator

A regex data generator works backwards from a regular expression: instead of testing whether a string matches, it produces random strings that do. Paste the pattern your validator uses — an order code, a postcode, a token format — and get a batch of matching values, each verified against the pattern with the browser's own regex engine.

It is the fastest way to test a validator from the inside: if the generator produces a value your form rejects, the form and the pattern disagree, and one of them is wrong.

How to use it

  1. Type a pattern, or start from a preset: order code, hex token, licence plate, semver, IPv4-shaped string or UK postcode.
  2. Keep verify each result on to get a Matches column.
  3. Generate a batch and paste the values into the field, API or test that uses the same pattern.
  4. Export as JSON or CSV to use as a parameterised test table.

What you can control

  • Character classes and ranges ([A-Z0-9]), negated classes ([^aeiou]), and the escapes \d, \w, \s, \D, \W, \S.
  • Groups, non-capturing groups ((?:…)) and alternation (ab|cd).
  • Quantifiers ?, *, +, {n}, {n,} and {n,m}, with ranges up to 200.
  • Verification of every value against your pattern.
  • Clear errors for unsupported features instead of silent wrong output.

Examples

Pattern Sample output
[A-Z]{2}-\d{4}-[a-z0-9]{6} LM-6592-e5np5c
(?:ab|cd){2} cdcd
^[A-Z]{1,2}\d[A-Z\d]? \d[ABD-HJLNP-UW-Z]{2}$ U4M 0QG
\w+@example\.com r@example.com
[^aeiou]{5} RxJSl

Notice the last two. \w+ happily produces a one-character local part, and [^aeiou] matches uppercase vowels and digits too. That is the other use of this tool: seeing what a pattern really permits. If the samples surprise you, the pattern is looser than you thought.

Using it in a parameterised test

import samples from "./fixtures/order-codes.json"; // generated from the same pattern

describe("order code validator", () => {
  test.each(samples.map((s) => s.Value))("accepts %s", (code) => {
    expect(isValidOrderCode(code)).toBe(true);
  });
});

Pair it with near-misses for the negative half: drop the last character, add one, lowercase a letter. Each should be rejected.

What this is not

This generates matching strings; it does not explain or debug a pattern, and it does not support look-around or back-references. Values are drawn uniformly from each class, so they are valid but rarely realistic — use the dedicated generators for things like emails, IPs and postcodes when realism matters.

Questions

Which regex syntax is supported?

Literals, character classes and ranges, negated classes, the escapes \d \w \s and their negations, the dot, capturing and non-capturing groups, alternation, and the quantifiers ?, *, +, {n}, {n,} and {n,m}. Anchors ^ and $ are accepted and ignored, since a generated string is always the whole match.

What is not supported?

Look-ahead, look-behind, named groups and back-references. Patterns using them get a clear error instead of a string that only looks right. Rewrite a look-ahead as an explicit class or alternation and it usually works.

How long can unbounded quantifiers get?

* and + repeat up to six times, so output stays readable. If you need longer strings, use an explicit range such as {20,60}; ranges are allowed up to 200.

Are the strings guaranteed to match?

Yes. With verification on, every value is tested against your pattern using the browser's own RegExp engine, and the result is shown in a Matches column. A false would mean a bug in the generator, and is worth reporting.

Can I generate strings that do NOT match?

Not directly. For negative tests, take a matching value and break it — remove a character, add one, change a case — or use the boundary value and malformed data generators, which produce near-misses on purpose.

Next in Developer

All 11 →