Utilora

Pattern Generator - Learn String Rules from Examples

Data Tools

What is Pattern Generator - Learn String Rules from Examples?

Pattern Generator learns classification rules from examples by training a CART decision tree on string features. You provide positive examples (strings that should match) and negative examples (strings that shouldn't), and the tool extracts the structural rules that distinguish them. This is useful when you know what makes a valid input but struggle to write the regex — the tree learns the logic for you and exports it as production-ready code.

How it works

Each input string is featurized into 15 numeric features: length, digit count, uppercase count, lowercase count, special char count, whether it starts/ends with digits or letters, and others. The CART decision tree is trained on these features using Gini impurity splitting. The tree structure is then walked to produce rules: for example, if length < 10 and contains '-' then valid. The rules are exported as Rust match expressions, JavaScript switch/if chains, or a best-effort regex.

Features & Benefits

  • 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

Popular Utilities