Core\Regex\Match
One match of a regular expression in a text. It has the matched text, the position where the match starts and the text of each group. Core\Regex::match and Core\Regex::matchAll return it.
Core\Regex::match returns a Core\Regex\Match, or null when nothing matched. Core\Regex::matchAll returns a list of them, and Core\Regex::replaceWith gives one to its callback. You never create one yourself. text() returns the whole match. group() returns one group by number or by name. It returns null for a group the pattern declares but this match did not use. groups() returns every group in pattern order: a named group appears under its name, then under its number. offset() returns where the match starts, counted in graphemes.
<?nvsvar $m = Core\Regex::match('café au lait', '(?<drink>lait)');if ($m != null) { echo $m->text(), ' ', $m->offset(), ' ', $m->group('drink') ?? '?', ' ', $m->group(1) ?? '?', "\n"; foreach ($m->groups() as string $k => ?string $v) { echo $k, '=', $v ?? 'null', ';'; } echo "\n";}var $opt = Core\Regex::match('ac', '(a)(b)?(c)');echo $opt?->group(2) ?? 'no b', ' ', $opt?->group(3) ?? 'no c', "\n";lait 8 lait lait0=lait;drink=lait;1=lait;no b cReturned by
You get a Core\Regex\Match from these methods:
Members
4 members.
