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.
Natural language description of the desired regex pattern. Examples: "email address", "phone number with dashes", "text that starts with A"
Optional test string to validate the generated pattern against and improve confidence scoring. If provided, the function will test the pattern and adjust confidence based on whether the test passes.
A TextExtractionResult
object containing:
success
: Boolean indicating if pattern generation succeededpattern
: Generated RegExp object (undefined if failed)confidence
: Number between 0-1 indicating pattern reliabilitydescription
: Human-readable description of the generated patternsuggestions
: Array of helpful suggestions for improvement// Basic email pattern
const result = humanToRegex("email address");
console.log(result.pattern); // /^[^\s@]+@[^\s@]+\.[^\s@]+$/
// Complex positional pattern
const startPattern = humanToRegex("starts with 'user_' followed by numbers");
// With test validation
const phoneResult = humanToRegex("US phone number", "+1-555-123-4567");
console.log(phoneResult.confidence); // Higher confidence due to successful test
Converts human-readable text descriptions into regular expression patterns. This is a convenient alias for
parseHumanTextToRegex
that provides the same functionality with natural language processing to understand pattern requirements.