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 →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
- Enter a regular expression and toggle any flags.
- Choose how many examples you want; they are generated and verified live.
- Copy an individual sample, or “Copy all”.
- 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
Case Converter
Convert text between camelCase, PascalCase, snake_case, CONSTANT_CASE, kebab-case, Title Case, and more — all at once, in your browser.
Diff Viewer
Compare two texts or code snippets side by side with line-level difference highlighting.
Image to Text (OCR)
Extract the text from a screenshot, photo, or scanned document with OCR — in 18 languages, entirely in your browser. Nothing is uploaded.
Markdown Editor
Write Markdown with a live GitHub-flavored preview, a table of contents, and one-click export to Markdown or HTML — entirely in your browser, nothing uploaded.
Mojibake Fixer
Repair garbled text where UTF-8 was misread as Windows-1252 — turn “café” back into “café” and “’” back into “’”. Runs entirely in your browser.
Regex Railroad Diagram
Visualize a regular expression as a railroad diagram and read a plain-English, step-by-step explanation. Hover to link the two. Runs in your browser.