$label) { if ($label !== '*') { $labels[$key] = normalizeName($label); } } $rule = \implode('.', $labels); $regexParts = []; foreach (\explode('.', $rule) as $part) { if ($part === '*') { $regexParts[] = '[^.]+'; } else { /** @noinspection PregQuoteUsageInspection */ // We use (), so we don't have that problem $regexParts[] = \preg_quote($part); } } return \array_reduce($regexParts, static function (string $carry, string $item) use ($exception): string { if ($carry === '') { return $item; } return $item . "(?:\\." . $carry . ')' . ($exception ? '' : '?'); }, ''); } private function __construct() { // no instances should be built } }