Skip to main content

Compiles a regex and reports a binary match / mismatch against the model’s output — handy for asserting format invariants like phone numbers, currency strings, UUIDs, or identifier prefixes without paying for a model call.

For a zero-code option, see the pre-built Regex Match metric. Use the version below when you want to extend the logic — capture groups, multiple alternative patterns, richer explanations.

Code#

Both re.search and String.match find a match anywhere in the string. If you need the entire output to match, switch to re.fullmatch in Python, or anchor the pattern with ^...$ in TypeScript.

Input mapping#

ParameterBind to
outputThe model output, usually output.
patternUse a literal regex string (e.g. ^[A-Z]{3}-\d{4}$) when every example shares the same pattern, or a dataset path (e.g. metadata.expected_pattern) when patterns vary per example.

Output configuration#

Categorical labels:

LabelScore
match1.0
mismatch0.0
missing0.0
invalid_pattern0.0

Optimization direction: maximize.

Runtime requirements#

SettingValue
SandboxAny — works in the in-process WebAssembly (Python) or Deno (TypeScript) backends.
DependenciesNone — uses re / built-in RegExp.
Internet accessNot required.
Environment variablesNone.
Warning

Untrusted regex patterns can be vulnerable to catastrophic backtracking (ReDoS). If pattern is sourced from per-example dataset values rather than a fixed literal, prefer patterns from a trusted column you control.