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 specifying the desired regex pattern behavior. Supports all pattern types: simple keywords, complex multi-part requirements, length constraints, character classes, and specialized format patterns.
Optional test input for pattern validation and confidence calculation. Enables immediate verification that the generated pattern works as expected.
Complete TextExtractionResult
object with comprehensive pattern data:
success
: Whether text parsing and pattern generation succeededpattern
: Ready-to-use RegExp object (undefined if generation failed)confidence
: Numerical confidence score indicating pattern reliabilitydescription
: Human-readable explanation of the pattern's matching behaviorsuggestions
: Actionable advice for pattern improvement or troubleshooting// Compact pattern creation
const uuid = t2r("uuid format");
const valid = uuid.pattern?.test("550e8400-e29b-41d4-a716-446655440000");
// Quick validation pipeline
const result = t2r("alphanumeric 8-16 chars", "password123");
console.log(`Confidence: ${result.confidence}, Valid: ${result.success}`);
// Streamlined error handling
const pattern = t2r("complex requirement").pattern || /fallback/;
Efficient text-to-regex transformation with streamlined syntax. This abbreviated alias for
parseHumanTextToRegex
maintains full functionality while providing a more concise interface for frequent pattern generation tasks and integration into larger text processing workflows.