Regex Generator from Examples (Rule Based)

Describe what you want with examples instead of syntax and get a regular expression back, tested against all of them.

Use the tool

Why this tool exists

The generator first tries a library of common patterns (email, URL, ISO date, UUID, IPv4, hex colour, time, version, slug, numbers) and keeps those that match every positive and no negative example. Otherwise it generalises your examples by character class (digit, upper, lower, space, punctuation) and learns the length ranges per position when all examples share the same shape. As a last resort it lists the literals as an alternation.

The result is only as good as your examples: give varied positives and the tricky negatives. Always review it, and prefer a validated library for emails and URLs.

No data is sent anywhere: the work happens in your browser, so you can use it offline once the page has loaded.

How to use it

  1. Enter strings that must match, one per line.
  2. Optionally enter strings that must not match.
  3. Run it and pick a candidate.
  4. Test it in the regex tester with more data.

Frequently asked questions

Is this machine learning?

No. It is a rule-based generaliser with a small pattern library.

Why did it fail?

No pattern fit all positives without matching a negative; remove a conflicting example or add more.

Can it handle optional parts?

Only when lengths vary within one segment. Examples with different structures fall back to an alternation.

Is my data sent anywhere?

No. Everything is processed in your browser, and the page makes no network requests with your input.