The more examples you give, the better the pattern fits. Each line is trimmed and blank lines are ignored.

Pattern options
Flags
Generated pattern

      

Matches

    

How the regex generator works

Every sample is split into runs of digits, letters and punctuation. Those runs are lined up across your samples and widened wherever the samples disagree, so the final pattern is the tightest one that still matches every example you gave.

The pattern uses JavaScript regex syntax, which also works in Java, Python, PHP, Go and most editors. Everything runs in your browser - your samples are never uploaded.

Worked example: matching order references

Say you need to pull order references out of a log file and you have three of them to hand. Paste these into the samples box, one per line:

ORD-2024-0001
ORD-2023-4517
ORD-2025-0099

Leave the detail level on Balanced, the match scope on Anywhere in the text, and the g flag ticked. Press Generate Regex and you get:

[A-Z]{3}-\d{4}-\d{4}

The explanation underneath breaks that into three uppercase letters, the character -, four digits, another -, and four more digits. The copy buttons give you either the bare pattern or the full literal /[A-Z]{3}-\d{4}-\d{4}/g for pasting into JavaScript.

Switch the detail level to Loose and the exact counts relax into + quantifiers, so references with a different number of digits still match. Switch the match scope to Whole line only and the pattern gains ^ and $, so it matches only lines that contain nothing else.

Common uses

Frequently asked questions

Which regex flavour does it produce?

JavaScript regular expression syntax. The constructs it uses are the common ones, so the same pattern also works in Java, Python, PHP, Go, Ruby and most code editors and command line tools.

Why did I get a generic email pattern instead of one built from my samples?

When every sample fits a known format - email address, URL, IPv4 address, UUID, date, time, phone number, hex colour or number - the proven pattern for that format is used instead, and a notice says so. Untick Detect common formats to build a pattern from your samples instead.

What is the difference between balanced, loose and strict?

Balanced uses character classes with exact repeat counts, so a three letter prefix becomes [A-Z]{3}. Loose keeps the same classes but uses + quantifiers so lengths can vary. Strict escapes the literal text of each sample and joins them with |.

What happens if my samples have completely different shapes?

The generator first tries merging neighbouring letter and digit runs so the samples line up, and tells you when it has done that. If they still do not line up, each shape becomes its own alternative separated by |, and it suggests removing the odd sample out for a tidier pattern.

Are my sample strings uploaded anywhere?

No. The pattern is built and tested entirely in your browser, so neither your samples nor the text you paste into the tester leaves your device.

Related tools