Regex From Examples
Processed Client SidePaste 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.
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
- Paste three or more real strings you want to match into the top pane, one per line.
- Add strings that must not match to the lower pane — near misses are the most useful ones.
- Pick a strictness level: start with Strict and loosen it if a valid example is rejected.
- Read the breakdown to check the pattern means what you think it means.
- Check the verification list — every "must match" line should be green and every "must not match" line rejected.
- 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.