Skip to content
Tezmy Tools

Random Text from Regex

Generate random strings that match a regular expression

Without slashes, or as /pattern/flags. Example: (cat|dog)s? or [a-z]{5}@example\.com

These have no upper limit in a regex, so a cap is needed.

Supports character sets, groups, alternatives (a|b), quantifiers ({2,5}, *, +, ?), \\d \\w \\s and back-references like \\1. Anchors and \\b are ignored; lookarounds aren't supported.

Runs in your browser. Nothing is uploaded.

About the Random Text from Regex

Writing test data by hand is slow. This generator works backwards from a regular expression: give it a pattern such as [A-Z]{3}-\d{4} and it produces random strings that match, like KQT-4831. It understands character sets, ranges, groups, alternatives, the usual quantifiers, shorthand classes like \d and \w, and even back-references. Make one example or a thousand, keep them unique if you need to, then copy or download the list. Everything is generated in your browser with a secure random source.

Updated October 2026

How to use the Random Text from Regex

  1. 1Type your regular expression, with or without the slashes.
  2. 2Set how many strings you want.
  3. 3Set the most repeats for * and +, which have no limit of their own.
  4. 4Tick No duplicates if every string must be different.
  5. 5Press Generate, then copy or download the list.

Useful patterns to start with

Copy one of these and adjust it to your format.

  • Order number: ORD-\d{6}
  • Product code: [A-Z]{2}\d{3}-[A-Z0-9]{4}
  • UK postcode style: [A-Z]{1,2}\d{1,2} \d[A-Z]{2}
  • Hex colour: #[0-9a-f]{6}
  • Date: 20(2[0-9])-(0[1-9]|1[0-2])-(0[1-9]|1\d|2[0-8])
  • Username: [a-z][a-z0-9_]{4,11}

Testing validation rules

If your form or API validates input with a regex, generate a few hundred strings from the same pattern and send them through your code. Every one should pass. Then change the pattern slightly, for example one digit too many, to create strings that should fail. This catches mistakes in validation code quickly.

How each part is filled

A set like [A-Z] picks one of its characters with equal chance. A negated set like [^0-9] picks from printable ASCII characters that aren't in the set. The dot picks any printable ASCII character. A quantifier picks a repeat count between its minimum and maximum, each equally likely, so {2,5} gives lengths 2, 3, 4 and 5 equally often.

Getting unique values

Tick No duplicates when you need distinct IDs. If the pattern can only make a few different strings, such as [ab] with two possibilities, the tool makes as many as exist and tells you.

Escaping special characters

Characters such as . * + ? ( ) [ ] { } | and the backslash have special meanings in a regex. To get them literally, put a backslash in front: \. for a full stop, \( for a bracket. Inside a set, most of them lose their meaning, so [.+] simply means a full stop or a plus sign. If the output contains characters you didn't expect, an unescaped dot is the usual reason, because it matches any character.

Phone and computer

Type the pattern on any device. The list scrolls sideways for long strings, and Download saves it as a text file for your tests. To test your pattern first use the Regex Tester, and for plain random letters use the Random String Generator.

Features

  • Character sets, ranges and negated sets
  • Groups, alternatives and back-references
  • Quantifiers {n}, {n,m}, *, + and ?
  • Shorthand \d, \w, \s and their opposites
  • Unique-only option
  • Copy or download the results

Frequently asked questions

How does it turn a regex into text?

It reads the pattern into its parts and then builds a string by picking random characters from each set, a random option from each alternative and a random number of repeats within each quantifier.

Which regex features are supported?

Literal characters, escapes, [a-z] sets, [^…] negated sets, . (any printable character), groups, (?:…) and named groups, |, {n}, {n,}, {n,m}, *, +, ?, \d \w \s \D \W \S, \x and \u codes, and back-references like \1.

What isn't supported?

Lookahead and lookbehind, because they describe conditions rather than text. Anchors such as ^, $ and \b are accepted but ignored, since a generated string always starts and ends where the pattern does.

Why do I need a limit for * and +?

They mean any number of repeats, which could be infinite. The limit keeps strings a sensible length; set it to whatever your tests need.

Can I generate realistic emails or phone numbers?

Yes, with a suitable pattern, for example [a-z]{5,8}\.[a-z]{4,7}@example\.com or \+44 7\d{3} \d{6}. For real-looking names and addresses, our Fake Data Generator is better.

Are the strings random enough for passwords?

They use the browser's cryptographic random source, but a pattern can make passwords predictable. Use the Password Generator for real passwords.

Related tools