Build Regex from Example Strings
You know which strings should match but you don't want to write the regex by hand. Paste your examples — phone numbers, product codes, file paths — and this tool infers the pattern: literal where all examples agree, character classes where they differ. A generic-to-specific slider controls how loose the pattern is.
How to use the Build Regex from Example Strings
Paste example strings. The tool finds positions where all examples agree (becomes literal) and positions where they differ (becomes a character class). The slider adjusts how tight the pattern is:
- Loose — generic classes (\w, \d, .)
- Balanced — character ranges where appropriate
- Strict — specific character sets seen in examples
- Literal — alternation of all examples
From sample strings to a pattern, with a tightness dial
This builder lines your example strings up by position and looks at each column. Where every example agrees on a character, the output keeps it as a literal; where they differ, it emits a character class covering what it saw. The result is a pattern shaped exactly like your data — perfect for fixed-format strings such as SKU-2026-001.
A specificity slider controls how tight that class is. Loose uses broad shorthands (\w, \d, .); balanced uses sensible ranges; strict restricts each position to the exact characters observed; and literal falls back to alternating the whole inputs. You dial in how much new input you want the pattern to accept.
Common use cases
- Product and SKU codes — derive a validator from a list of real codes in seconds.
- Fixed-format identifiers — match invoice numbers, ticket refs, or part numbers that follow a template.
- File-naming conventions — build a pattern that accepts your naming scheme and rejects stray files.
- Generating a regex from sample data — when you have the data but cannot write the pattern by hand.
- Tuning strictness — slide between a forgiving and a locked-down pattern to suit the job.
Frequently asked questions
How is this different from the "regex from examples" tool?
What if my examples have different lengths?
Does the pattern anchor to the whole string?
^...$ so it must match the entire value; turn it off to allow the pattern to match inside a larger string.