DevTools

Regex Sample Generator

Generate example strings that match a regular expression, then send them straight into the Regex Tester. Every sample is verified to match — all in your browser.

Prefer the terminal? See the CLI equivalent →
Loading tool…

About the Regex Sample Generator

  • Generates matching strings
  • Every sample verified to match
  • Send into the Regex Tester
  • Instant results
  • 100% private — runs in your browser
  • Free, no sign-up

Type a regular expression and get example strings that match it. Instead of guessing test inputs by hand, generate a batch of valid samples — useful for building test fixtures, sanity-checking a pattern, or understanding what a regex actually accepts.

It completes the regex trio: pair it with the Regex Tester and the Regex Diagram. Generate samples here, then send them straight into the Tester as its subject text, or open the same pattern in the railroad Diagram to see its structure.

Every sample is verified: each candidate is generated from the pattern’s structure and then tested against the real regular expression, so a string is only shown if it genuinely matches. Nothing is uploaded — it all runs in your browser.

How to use it

  1. Enter a regular expression and toggle any flags.
  2. Choose how many examples you want; they are generated and verified live.
  3. Copy an individual sample, or “Copy all”.
  4. Send them into the Regex Tester, or open the pattern in the Diagram.

What it can and can’t sample

Literals & quantifiers
a, ab+c, colou?r, x{2,4} — fully supported.
Classes & ranges
[a-f0-9], [^0-9] — a permitted character is picked at random.
Meta escapes
\d \w \s and . map to representative characters.
Groups & alternation
(cat|dog), (ab)+ — one branch is chosen per sample.
Backreferences
\1 / \k<name> reproduce the captured text.
Lookarounds
Best-effort: candidates that don’t satisfy them are dropped, never shown wrong.

Frequently asked questions

Are the generated strings guaranteed to match?+

Yes. Each candidate is validated against your actual regular expression before being shown, so every listed sample truly matches. Constructs that are hard to satisfy directly (like lookaheads) simply yield fewer samples rather than incorrect ones.

Why do I sometimes get fewer samples than I asked for?+

The tool returns only distinct, verified matches. If a pattern has few possible matches (e.g. a fixed string) or relies heavily on lookarounds, there may not be enough unique valid strings to reach your requested count.

Why did the samples change when I edited the pattern?+

Samples are seeded from the pattern and flags, so the same input gives the same list — and the Regenerate button reshuffles to a new set. Editing the pattern naturally produces different examples.

Can I use these as test data?+

Yes — that’s a primary use. Generate a batch, copy them all, and drop them into fixtures or send them into the Regex Tester to see exactly how each one matches.

Works well with

Regex Sample Generator chains with these tools — send your result straight on:

Related tools