Const
Parses a human-readable string to generate a regular expression. It first attempts to find complex, compound patterns, then looks for direct keyword matches, and finally falls back to constructing a pattern from individual text components.
The natural language string describing the desired regex.
Optional
testValue: stringAn optional string to test against the generated regex for confidence scoring.
A TextExtractionResult
object containing the generated pattern, confidence, and other metadata.
Descriptive text explaining the pattern requirements. Supports complex descriptions like: "alphanumeric with dashes between 5 and 50 characters", "email that contains numbers in domain", "text starting with capital and ending with period"
Optional validation string to test pattern accuracy and boost confidence. When provided, the generated regex is tested against this value to ensure correctness.
Complete TextExtractionResult
with pattern, confidence metrics, and guidance:
success
: Whether the text was successfully parsed into a patternpattern
: The generated RegExp ready for use (null if parsing failed)confidence
: Reliability score from 0.0 (low) to 1.0 (high confidence)description
: Clear explanation of what the pattern matchessuggestions
: Actionable advice for improving pattern or handling edge cases// Simple pattern conversion
const digits = textToRegex("exactly 5 digits");
// Result: /^\d{5}$/
// Complex compound pattern
const complex = textToRegex("username that starts with letter, contains numbers, and is 3-20 characters");
// Financial pattern with validation
const creditCard = textToRegex("credit card number", "4532-1234-5678-9012");
if (creditCard.success) {
console.log(`Pattern confidence: ${creditCard.confidence}`);
}
Transforms textual pattern descriptions into executable regular expressions. This is an intuitive alias for
parseHumanTextToRegex
that emphasizes text-to-regex conversion capability, supporting complex multi-part requirements and natural language.