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.
Concise natural language pattern description. Same capabilities as the full function: complex patterns, compound requirements, positional constraints, and specialized domain patterns (email, phone, etc.)
Optional validation string for confidence boosting and accuracy testing. When provided, tests the generated pattern and adjusts confidence accordingly.
Standard TextExtractionResult
with full pattern generation results:
success
: Pattern generation success indicatorpattern
: Generated RegExp object for immediate useconfidence
: Reliability score from 0.0 to 1.0description
: Clear explanation of pattern behaviorsuggestions
: Improvement recommendations and usage tips// Quick email pattern
const email = h2r("email");
// Rapid validation setup
const phone = h2r("US phone", "+1-555-0123");
if (phone.success && phone.confidence > 0.8) {
// Use phone.pattern for validation
}
// Inline pattern generation
const isValid = h2r("starts with A ends with Z").pattern?.test("AMAZING");
Quick human-to-regex conversion with abbreviated syntax. This compact alias for
parseHumanTextToRegex
provides the same powerful natural language processing in a shortened form ideal for rapid development and inline pattern generation.