RegexField
extends BaseField
in package
Typed F-DSL wrapper for PCRE-pattern matching over a string-valued chain. The match operation reads the running string off the chain, runs `preg_match` against it, and either rejects (no match) or accepts — optionally injecting the match payload as kwargs.
Two output modes:
-
captureGroups: false(default) — bool verdict. The Filter accepts when the pattern matches and rejects otherwise; no kwargs are injected into the dispatcher. -
captureGroups: true— kwarg injection. On a successful match the Filter emits['regexp_match' => $matches[0], 'regexp_groups' => $matches]so handlers can destructure named and numbered captures. The dict keys mirror aiogram's regex-filter contract (see spec § "Magic-filter runtime + F-DSL");regexp_matchis the full matched substring andregexp_groupsis the fullpreg_matchoutput array (group 0 plus numbered/named captures).
The PCRE pattern is wrapped with #…#u delimiters internally so users
pass naked patterns — matching the convention MagicFilter::regexp()
already uses. The \A anchor is implicit (match from the start of the
string) for parity with Python re.match.
Table of Contents
Properties
Methods
- __construct() : mixed
- Hold the chain handle directly: codegen passes a freshly-rooted chain (e.g. `MagicFilter::root()->text`) and subclass methods clone-and- extend it via the chain's immutable append semantics.
- asFilter() : Filter
- Bridge the wrapped chain to a `Filter`. Used by callers that want the raw chain verdict without going through a typed comparator — e.g. an existence check on a nullable-typed field where the underlying `MagicFilter::asFilter()` reject-on-null behaviour is exactly what the user wants.
- matches() : Filter
- Wrap the chain's string output in a `preg_match` predicate.
Properties
$chain read-only
public
MagicFilter
$chain
Methods
__construct()
Hold the chain handle directly: codegen passes a freshly-rooted chain (e.g. `MagicFilter::root()->text`) and subclass methods clone-and- extend it via the chain's immutable append semantics.
public
__construct(MagicFilter $chain) : mixed
Parameters
- $chain : MagicFilter
asFilter()
Bridge the wrapped chain to a `Filter`. Used by callers that want the raw chain verdict without going through a typed comparator — e.g. an existence check on a nullable-typed field where the underlying `MagicFilter::asFilter()` reject-on-null behaviour is exactly what the user wants.
public
asFilter() : Filter
Returns a MagicFilterAsFilter instance under the hood; see
MagicFilterAsFilter for the bool|array acceptance contract.
Return values
Filtermatches()
Wrap the chain's string output in a `preg_match` predicate.
public
matches(string $pattern[, bool $captureGroups = false ]) : Filter
Parameters
- $pattern : string
- $captureGroups : bool = false
-
When
true, emit a{regexp_match, regexp_groups}kwarg payload on accept. Whenfalse, surface a plain bool.