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
- Type a pattern, or start from a preset: order code, hex token, licence plate, semver, IPv4-shaped string or UK postcode.
- Keep verify each result on to get a
Matchescolumn. - Generate a batch and paste the values into the field, API or test that uses the same pattern.
- 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.