phpbotgram

RegexField extends BaseField
in package

FinalYes

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:

  1. captureGroups: false (default) — bool verdict. The Filter accepts when the pattern matches and rejects otherwise; no kwargs are injected into the dispatcher.

  2. 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_match is the full matched substring and regexp_groups is the full preg_match output 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

$chain  : MagicFilter

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

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
Filter

matches()

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. When false, surface a plain bool.

Return values
Filter
On this page

Search results