| @@ 76-83 (lines=8) @@ | ||
| 73 | * | |
| 74 | * @throws RegexFailed | |
| 75 | */ | |
| 76 | public function group(int $index): string | |
| 77 |     { | |
| 78 |         if (! isset($this->matches[$index])) { | |
| 79 | throw RegexFailed::indexedGroupDoesntExist($this->pattern, $this->subject, $index); | |
| 80 | } | |
| 81 | ||
| 82 | return $this->matches[$index]; | |
| 83 | } | |
| 84 | ||
| 85 | /** | |
| 86 | * Match group by name. | |
| @@ 94-101 (lines=8) @@ | ||
| 91 | * | |
| 92 | * @throws RegexFailed | |
| 93 | */ | |
| 94 | public function namedGroup(string $groupName): string | |
| 95 |     { | |
| 96 |         if (! isset($this->matches[$groupName])) { | |
| 97 | throw RegexFailed::namedGroupDoesntExist($this->pattern, $this->subject, $groupName); | |
| 98 | } | |
| 99 | ||
| 100 | return $this->matches[$groupName]; | |
| 101 | } | |
| 102 | } | |
| 103 | ||