Regex from Examples
Paste examples of strings that should match (one per line); the tool infers a regex that matches all of them. Useful when you know the shape of what you want to extract but don't want to write the regex by hand. Common patterns (emails, dates, hex IDs, phone numbers) are detected and handled.
How to use the Regex from Examples
Paste the strings you want to match, one per line. Optionally paste counter-examples to refine. The tool tries three strategies: character-class-per-position (good for fixed-shape inputs like IDs), pattern detection (recognizes dates, emails, URLs, hex colors), or literal alternation (when the inputs are unrelated). The generated regex is validated against your examples.
How pattern inference works here
Give the tool a column of strings that should match and it generalises them into one regex, using one of three strategies. Character class per position compares the examples column by column and builds a class for each spot — ideal for fixed-shape inputs like order IDs. Pattern detection recognises common shapes (dates, emails, hex colours, phone numbers) and emits the idiomatic pattern for them. Literal alternation simply ORs the inputs together when they share no structure.
Optional negative examples — strings that must not match — tighten the result by ruling out an over-broad pattern. Inference is a heuristic, not magic: the generated regex is checked against your examples, but you should still read it and tighten anything too permissive before relying on it.
Common use cases
- Extracting known-shape values — build a matcher for IDs, SKUs, or reference codes from a handful of samples.
- Scraping log lines — turn a few example lines into a pattern that pulls the same field from all of them.
- Drafting a validator — get a first-pass pattern for a format you can describe by example but not from memory.
- Recognising common formats — let pattern detection hand you a tested date or email regex.
- Learning by example — see how sample strings translate into regex constructs.