| @@ 38-53 (lines=16) @@ | ||
| 35 | * |
|
| 36 | * @throws \Spatie\Regex\RegexFailed |
|
| 37 | */ |
|
| 38 | public static function for(string $pattern, string $subject) |
|
| 39 | { |
|
| 40 | $matches = []; |
|
| 41 | ||
| 42 | try { |
|
| 43 | $result = preg_match_all($pattern, $subject, $matches); |
|
| 44 | } catch (Exception $exception) { |
|
| 45 | throw RegexFailed::match($pattern, $subject, $exception->getMessage()); |
|
| 46 | } |
|
| 47 | ||
| 48 | if ($result === false) { |
|
| 49 | throw RegexFailed::match($pattern, $subject, static::lastPregError()); |
|
| 50 | } |
|
| 51 | ||
| 52 | return new static($pattern, $subject, $result, $matches); |
|
| 53 | } |
|
| 54 | ||
| 55 | public function hasMatch(): bool |
|
| 56 | { |
|
| @@ 37-52 (lines=16) @@ | ||
| 34 | * |
|
| 35 | * @throws \Spatie\Regex\RegexFailed |
|
| 36 | */ |
|
| 37 | public static function for(string $pattern, string $subject) |
|
| 38 | { |
|
| 39 | $matches = []; |
|
| 40 | ||
| 41 | try { |
|
| 42 | $result = preg_match($pattern, $subject, $matches); |
|
| 43 | } catch (Exception $exception) { |
|
| 44 | throw RegexFailed::match($pattern, $subject, $exception->getMessage()); |
|
| 45 | } |
|
| 46 | ||
| 47 | if ($result === false) { |
|
| 48 | throw RegexFailed::match($pattern, $subject, static::lastPregError()); |
|
| 49 | } |
|
| 50 | ||
| 51 | return new static($pattern, $subject, $result, $matches); |
|
| 52 | } |
|
| 53 | ||
| 54 | public function hasMatch(): bool |
|
| 55 | { |
|