Skip to content
gohacks.dev
Testing

Regex String Generator

Generate random strings that match a regular expression, such as order numbers, codes or hostnames, and check each one against the pattern.

Free · No sign-up · Your inputs stay in your browser

Input

Generate strings that match a regex

Output

Press Generate

Supports literals, character classes and ranges, \d \w \s and their negations, ., groups, alternation and the quantifiers * + ? {n} {n,m}. Unbounded quantifiers are capped at a few repeats so the output stays readable. Each result is checked against the pattern with the browser's own regex engine; lookarounds and backreferences are ignored when generating, so a pattern relying on them may produce strings that fail the check, and the count says how many.

Runs in this browser. Nothing you paste is sent to a server.

Test data in the shape you need

Fixtures need ids that look like production ones, fuzz tests need many valid inputs, and validation rules need examples on both sides of the line. Writing the format once as a regex and generating from it keeps the data and the rule in sync. Libraries such as randexp in JavaScript and Hypothesis's from_regex in Python do this in code.

Limits

Lookaheads, lookbehinds and backreferences cannot be generated forwards and are ignored, so a pattern that depends on them may produce non-matching strings; the check reports how many.

Share

Frequently asked questions

Can I generate strings that do not match, for negative tests?
Not directly. Generate valid ones, then change one character or add one, and confirm with the regex tester that they fail.
Why are some outputs much shorter than others?
* and ? allow zero repeats, so optional parts are sometimes empty. Use + or explicit counts for parts that must appear.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools