Free online tool

Regex Generator from Text

Paste examples of the text you want to match and get a tested regular expression, explained in plain English, with code for your language.

Generate a regular expression

Paste a few examples of the text you want to match and get a tested pattern, or start from a common one. Then read what it means, test it on your own text and copy code for your language.

Start from

Flags
What this regex means
PartMeaning

Test it


          

Use it in code

Everything runs in your browser; examples and test text are never uploaded or stored. Patterns use JavaScript syntax, which Python, PHP, Java, C# and Go read the same way for everything the generator writes.

Patterns from your examples

Paste a few strings that should match and, if you like, some that should not. The generator suggests patterns from strict to loose and shows how many of your examples each one matches and rejects.

Plain-English explanation

Every part of the pattern is listed with what it does, from character classes and quantifiers to groups, lookarounds and backreferences, so you can check a regex before you use it.

Live tester and code snippets

Highlight matches in your own text, line by line or all at once, and copy ready-to-run code for JavaScript, Python, PHP, Java, C# or Go with the right escaping and flags.

How to generate a regex from text examples

  1. 1

    Paste examples of the text you want to match, one per line, and optionally a few that should not match.

  2. 2

    Choose whether the pattern should match the whole value or find matches inside longer text, then pick a suggestion.

  3. 3

    Read the plain-English explanation and test the pattern on your own text, line by line or as a whole.

  4. 4

    Copy the regex, or a ready-made code snippet for JavaScript, Python, PHP, Java, C# or Go.

What people use this tool for

  • Build a validation pattern for a form field such as an order number, product code or postal code.
  • Find dates, IDs or email addresses in log files and exported data.
  • Understand an unfamiliar regex from a codebase before you change it.
  • Port a regular expression from JavaScript to Python, PHP, Java, C# or Go.

Frequently Asked Questions

How does the regex generator create a pattern from examples?

It splits each example into runs of letters, digits, spaces and single punctuation marks. Punctuation that every example shares, in the same order, becomes fixed text, and the parts between become character classes such as \d or [A-Z] with a length. For INV-001, INV-042 and INV-317 it suggests ^INV-\d{3}$. Stricter and looser versions are offered too, each tested against your examples.

Why add text that should not match?

Examples alone cannot tell the generator how general to be. Non-matching examples rule out patterns that are too loose: with ORD-26-42 listed as a non-match, any suggestion that accepts it is marked as failing, and the recommended pattern is the first one that matches every positive example and rejects every negative one.

What is the difference between matching the whole value and searching inside text?

Whole value wraps the pattern in ^ and $, so the entire input must fit; use it to validate a form field or a file name. Searching inside text uses word boundaries instead, so the pattern finds matches within a sentence, a log file or a document. Add the g flag to find every match rather than the first.

Which common patterns are included?

There are 35, grouped by category: email addresses, URLs, domains, IPv4 and IPv6 addresses, hex colors, numbers and currency, dates and times in ISO, US and European order, US and international phone numbers, postal codes for the US, UK, Canada and India, UUIDs, semantic versions, MAC addresses, Base64, password rules and text clean-up patterns. Each loads with sample text that should and should not match.

Is a regex enough to validate an email address or a date?

Only partly. The email pattern catches mistakes such as a missing @ or domain, but the only real test of an address is sending a message to it. The date patterns check months 01–12 and days 01–31, so 2026-02-31 still matches; check real calendar dates in code after the regex passes.

Will the regex work in Python, Java or Go?

Patterns use JavaScript syntax, and everything the generator writes is shared by those languages. The code panel converts named groups to Python's (?P<name>) form, escapes the pattern for each language's string literals and maps flags to options such as re.IGNORECASE or RegexOptions.Multiline. Go's RE2 engine has no lookarounds or backreferences, and the Go snippet warns when a pattern uses them.

Why does the tester say my pattern took too long?

Patterns with nested repeats, such as (a+)+ or (\w*)*, can try an exponential number of ways to match before failing, which is called catastrophic backtracking. The tester runs your pattern in a separate worker and stops it after 1.5 seconds, so the page never freezes. Remove the nested repeat or make the inner part more specific.

Is my text uploaded or saved?

No. Generation, testing and code all run in your browser, and your examples and test text are never sent anywhere or stored. Only your last starting point and code language are remembered, in this browser's local storage under zutilium:regex-generator.