Deterministic regex generator
Regex Generator
Build patterns from highlighted samples using tokenization, positional analysis, and LCS anchors.
Parsed samples: 3. Empty lines are ignored.
Generate mode variants and copy the one that fits your risk level.
Strict match
ValidatedINV-(?<digits>\d{4})-(?<digits_2>\d{5})$Balanced match
ValidatedINV-(?<digits>\d{4})-(?<digits_2>\d{5})$Loose match
ValidatedINV-(?<digits>\d+)-(?<digits_2>\d+)$Language exports
Active mode: balancedJavaScript
/INV-(?<digits>\d{4})-(?<digits_2>\d{5})$/Python
re.compile(r"INV-(?P<digits>\\d{4})-(?P<digits_2>\\d{5})$")PHP
'/INV-(?P<digits>\d{4})-(?P<digits_2>\d{5})$/'Golang
regexp.MustCompile(`INV-(?P<digits>\d{4})-(?P<digits_2>\d{5})$`)AST preview
Deterministic intermediate tree{
"type": "sequence",
"children": [
{
"type": "literal",
"value": "INV-"
},
{
"type": "namedGroup",
"name": "digits",
"child": {
"type": "class",
"classSource": "\\d",
"min": 4,
"max": 4
}
},
{
"type": "literal",
"value": "-"
},
{
"type": "namedGroup",
"name": "digits_2",
"child": {
"type": "class",
"classSource": "\\d",
"min": 5,
"max": 5
}
}
]
}[
{
"n": 1,
"start": 0,
"end": 14,
"text": "INV-2026-00123"
},
{
"n": 2,
"start": 35,
"end": 49,
"text": "INV-2025-77109"
},
{
"n": 3,
"start": 50,
"end": 64,
"text": "INV-2024-00991"
}
]Tokenization snapshot
Anchor tokens from LCS
Fixed tokens stay literal while variable slots are inferred from token frequencies and lengths.
How it works
The generator normalizes sample text, tokenizes each sample into typed segments, then infers fixed and variable slots with positional comparison and LCS anchors before building a regex AST and compiling strict, balanced, and loose patterns.
- Literal fragments are escaped safely and preserved in output.
- Generation avoids nested greedy quantifiers and validates each variant against samples.
Quick examples
Use balanced mode first, then tighten strict mode if the pattern is for validation.
Mini FAQ
Can I generate from one sample only?
Yes. You still get deterministic token inference, but multiple samples improve generalization quality.
Why do strict and loose patterns differ?
Strict keeps exact observed bounds, while loose widens variable quantifiers for more permissive matching.
Are results engine-safe?
Patterns use bounded classes without nested greediness, then each variant is validated against your samples.