mirror of
https://gh.wpcy.net/https://github.com/aspirepress/AspireCloud.git
synced 2026-06-01 00:19:09 +08:00
27 lines
761 B
PHP
27 lines
761 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Utils;
|
|
|
|
class Regex
|
|
{
|
|
/** @return string[] */
|
|
public static function match(string $pattern, string $subject): array
|
|
{
|
|
$matches = [];
|
|
\Safe\preg_match($pattern, $subject, $matches);
|
|
return $matches ?? []; // $matches cannot be null, but mago thinks otherwise ¯\_(ツ)_/¯
|
|
}
|
|
|
|
public static function replace(string $pattern, string $replacement, string $subject, int $limit = -1): string
|
|
{
|
|
$result = \Safe\preg_replace($pattern, $replacement, $subject, $limit);
|
|
assert(is_string($result)); // cannot be otherwise when the parameters are strings
|
|
return $result;
|
|
}
|
|
|
|
private function __construct()
|
|
{
|
|
// not instantiable
|
|
}
|
|
}
|