-
-
Notifications
You must be signed in to change notification settings - Fork 0
unifiers matchString()
Eugene Lazutkin edited this page Apr 3, 2026
·
5 revisions
Matches strings against regular expressions with optional capture group binding.
This unifier matches string values against a regular expression and can capture match groups into variables.
import matchString from 'deep6/unifiers/matchString.js';
import {variable} from 'deep6/env.js';
import unify from 'deep6/unify.js';
const matches = variable('matches');
const env = unify('user@example.com', matchString(/^(.+)@(.+)$/, matches));
// matches.get(env) === ['user@example.com', 'user', 'example.com']Arguments:
-
regexp— a requiredRegExpto match against. -
matches— an optional variable name or Variable to capture the full match array. -
props— an optional variable name or Variable to capture match properties (index,input).
Returns a MatchString unifier instance.
Extends Unifier. The constructor takes the same arguments as the factory function.
-
regexp— the RegExp used for matching. -
matches— the variable for capturing match array. -
props— the variable for capturing match properties.
-
unify(val, ls, rs)— attempts to matchvalagainst the regex.- Returns the match result (truthy) on success.
- Returns
falseifvalis a Variable or doesn't match.
import matchString from 'deep6/unifiers/matchString.js';
import {variable} from 'deep6/env.js';
import unify from 'deep6/unify.js';
const emailPattern = {
local: variable('local'),
domain: variable('domain'),
full: variable('full')
};
const matcher = {
local: matchString(/^[^@]+/, emailPattern.local),
domain: matchString(/@[^@]+$/, emailPattern.domain),
full: matchString(/^.+@.+$/, emailPattern.full)
};
const env = unify('user@example.com', matcher);
// All variables bound to captured valuesCore functions
Environments and variables
Unification
Traverse
Unifiers
Utilities