| @@ 67-74 (lines=8) @@ | ||
| 64 | return $this->matches[0] ?? null; |
|
| 65 | } |
|
| 66 | ||
| 67 | public function group(int $index): string |
|
| 68 | { |
|
| 69 | if (! isset($this->matches[$index])) { |
|
| 70 | throw RegexFailed::groupDoesntExist($this->pattern, $this->subject, $index); |
|
| 71 | } |
|
| 72 | ||
| 73 | return $this->matches[$index]; |
|
| 74 | } |
|
| 75 | ||
| 76 | /** |
|
| 77 | * @param string $group |
|
| @@ 82-89 (lines=8) @@ | ||
| 79 | * @return string |
|
| 80 | * @throws RegexFailed |
|
| 81 | */ |
|
| 82 | public function namedGroup(string $group): string |
|
| 83 | { |
|
| 84 | if (! isset($this->matches[$group])) { |
|
| 85 | throw RegexFailed::namedGroupDoesntExist($this->pattern, $this->subject, $group); |
|
| 86 | } |
|
| 87 | ||
| 88 | return $this->matches[$group]; |
|
| 89 | } |
|
| 90 | } |
|
| 91 | ||