/

Regex From Examples

Processed Client Side

Paste the strings you want to match and get a working regular expression, explained token by token and checked against every example — no AI, no upload.

Examples
Must match · 3Length: 36Lines: 3Size: 36 BytesCursor: 1:1
Must not match · 3Length: 41Lines: 3Size: 41 BytesCursor: 1:1
Regex
All 6 examples pass
Generated pattern
/^[A-Z]{3}-\d{4}-\d{1,4}$/
Exact lengths from your examples — {3,5} rather than +.
Breakdown
[A-Z]{3}exactly 3 uppercase letters
-the literal "-"
\d{4}exactly 4 digits
-the literal "-"
\d{1,4}1–4 digits
Checked against your examples
ORD-2024-1043matched
ORD-2023-88matched
ORD-2024-7matched
ORDER-2024-1043rejected
ord-2024-1043rejected
ORD-24-1043rejected
JavaScript usage
const pattern = /^[A-Z]{3}-\d{4}-\d{1,4}$/

if (pattern.test(input)) {
  console.log(input.match(pattern))
}

Bookmark this tool now — skip the search next time you need it.

About Regex From Examples

This tool runs entirely in your browser. Whatever you paste is processed on your own device and is never uploaded, logged, or sent to any server.

Write a regular expression by showing it what you want instead of assembling metacharacters by hand. Paste a handful of real strings — order IDs, log prefixes, timestamps, SKUs — and the tool splits each one into runs of digits, letters, and punctuation, lines those runs up across every example, and merges each column into the narrowest pattern that still covers all of them. Identical punctuation stays literal, varying runs widen into a character class, and the shortest and longest run you supplied become the quantifier, so \d{4}-\d{2}-\d{2} comes out of three dates rather than a vague .*. A second box holds the strings that must NOT match, and every example is re-tested against the finished pattern, so you can see at a glance whether the regex is too tight, too loose, or exactly right. Nothing is sent anywhere: the inference, the testing, and the generated code snippets all run in your browser, which matters when the examples come from production logs.

Key features

  • Builds a pattern from example strings — no regex syntax knowledge required to start
  • Negative examples: paste the strings that must be rejected and see whether the pattern is too broad
  • Three strictness levels — Strict pins exact lengths, Balanced keeps minimums open-ended, Loose reduces to character families
  • Plain-English breakdown of every part of the generated pattern, so you can read it before you ship it
  • Live verification: each example is marked matched or not matched against the finished regex
  • Suggests the strictness level that satisfies all your examples when the current one does not
  • Recognises common formats — email, URL, IPv4, UUID, ISO date, semver, hex colour, MAC and more — and says so
  • Copy-ready usage snippets for JavaScript, Python, PHP, Java, C# and Go, with the right escaping for each
  • Optional ^…$ anchoring and case-insensitive matching
  • Runs entirely client-side — production log lines and customer identifiers never leave the browser

How to use it

  1. Paste three or more real strings you want to match into the top pane, one per line.
  2. Add strings that must not match to the lower pane — near misses are the most useful ones.
  3. Pick a strictness level: start with Strict and loosen it if a valid example is rejected.
  4. Read the breakdown to check the pattern means what you think it means.
  5. Check the verification list — every "must match" line should be green and every "must not match" line rejected.
  6. Copy the pattern, or the ready-made snippet for your language, and paste it into your code.

Tips & common mistakes

  • Three or four examples produce a far better pattern than one. A single example can only ever be turned into a literal, because there is nothing to tell the tool which parts vary.
  • Include your edge cases: the shortest ID, the longest one, the one with the odd separator. The quantifier bounds come straight from the range you supply.
  • Negative examples are where the value is. Without them, a pattern that matches everything you pasted still looks like a success.
  • Strict is the right default for structured identifiers with fixed shapes. Loose is for free-form text where you only care about the character families.
  • Turn off anchoring when you plan to search inside a longer line rather than validate a whole string — with ^ and $ in place, the pattern only matches when the entire string is the value.
  • The generated regex is deliberately readable rather than clever. If you need a tighter rule — a real date validity check, or a full RFC-compliant email — start from this pattern and narrow it in the Regex Tester.
  • Backslashes need doubling in Java, C#, and most JSON config files. The usage snippets already handle that, so copy the snippet rather than the raw pattern when the destination is a string literal.

Related tools

Browse all 10 Code tools

Frequently asked questions

8

Paste the strings you want to match into the top pane, one per line, and the pattern appears immediately. The tool splits each example into runs of digits, letters, and punctuation, aligns those runs across all your examples, and merges them into the narrowest pattern that still matches every one.

Three or four is the sweet spot, and they should include your edge cases — the shortest value, the longest one, and anything with an unusual separator. A single example can only produce a literal pattern, because nothing indicates which parts are allowed to vary.

Strict pins the exact lengths seen in your examples, so three-to-five digits becomes {3,5}. Balanced keeps the minimum but leaves the upper bound open, as {3,} or +. Loose drops lengths entirely and widens letter classes to both cases, giving a pattern like [a-zA-Z]+-\d+.

It holds the near misses — strings that look similar but should be rejected. Every one of them is tested against the generated pattern, so if your regex is too broad you see it right away instead of discovering it in production.

No. The pattern is inferred by an algorithm that runs entirely in your browser, so it works offline, returns the same answer every time, and never uploads your examples. If you would rather describe the match in plain English, the AI Regex Generator does that instead.

Yes. The generated patterns use only syntax that is common to every major engine — character classes, quantifiers, and anchors. The usage snippet below the breakdown gives you the pattern already escaped and wrapped for JavaScript, Python, PHP, Java, C#, or Go.

Two usual causes: anchoring is turned off, so the pattern is allowed to match inside a longer string, and the strictness level is too loose for the job. Turn on ^…$, switch to Strict, and add the unwanted strings as negative examples.

No. The inference, the testing, and the snippet generation all happen locally in your browser, so pasting real log lines, order IDs, or customer references is safe.