Pattern Generator - Learn String Rules from Examples
Provide match and non-match string examples; a decision tree learns the pattern and exports it as Rust, JavaScript, or regex.
How to use
- 1
Add match examples
Enter strings that should match (e.g. valid emails, IDs, codes).
- 2
Add non-match examples
Enter strings that should NOT match.
- 3
Train and export
Click Train to fit the decision tree, then export as Rust, JavaScript, or a best-effort regex.
Why use this tool?
- Learns structural patterns without writing regex by hand
- Exports clean Rust or JavaScript validation functions
- Trains a CART decision tree on 15 string features in milliseconds
Frequently asked questions
- How many examples do I need?
- At least 4 match and 4 non-match examples. More examples improve accuracy.
- How accurate is the regex export?
- The regex is a best-effort approximation. The Rust and JS exports are exact and recommended for production use.
Related tools
Upload a CSV to auto-detect column types, spot missing values, and fit a linear regression - all locally in your browser.
Train a logistic regression model on A/B experiment observations and use what-if sliders to predict conversion probability.
Popular right now
Format, validate, and minify JSON instantly in your browser. Your data never leaves your device.
Decode JWT tokens and inspect header and payload instantly in your browser. Your tokens never leave your device.
Count words, characters, sentences, and estimate reading time instantly in your browser. No sign-up required.



