| @@ 86-93 (lines=8) @@ | ||
| 83 | * |
|
| 84 | * @throws RegexFailed |
|
| 85 | */ |
|
| 86 | public function group(int $index): string |
|
| 87 | { |
|
| 88 | if (! isset($this->matches[$index])) { |
|
| 89 | throw RegexFailed::indexedGroupDoesntExist($this->pattern, $this->subject, $index); |
|
| 90 | } |
|
| 91 | ||
| 92 | return $this->matches[$index]; |
|
| 93 | } |
|
| 94 | ||
| 95 | /** |
|
| 96 | * Match group by index or return default value if group doesn't exist. |
|
| @@ 123-130 (lines=8) @@ | ||
| 120 | * |
|
| 121 | * @throws RegexFailed |
|
| 122 | */ |
|
| 123 | public function namedGroup(string $groupName): string |
|
| 124 | { |
|
| 125 | if (! isset($this->matches[$groupName])) { |
|
| 126 | throw RegexFailed::namedGroupDoesntExist($this->pattern, $this->subject, $groupName); |
|
| 127 | } |
|
| 128 | ||
| 129 | return $this->matches[$groupName]; |
|
| 130 | } |
|
| 131 | } |
|
| 132 | ||