private function addSegment(string $segment): void
    {
        preg_match_all(
            "/\{(?'name'[a-z0-9_]++)(?::(?'pattern'(?:[^{}]++|\{(?&pattern)\})++))?\}/i",
            $segment,
            $matches,
            \PREG_SET_ORDER | \PREG_OFFSET_CAPTURE | \PREG_UNMATCHED_AS_NULL
        );

        if (empty($matches)) {
            $this->segments[] = $segment;
            $this->format .= $this->formatEncode($segment) . '/';
            return;
        }

        $pattern = $this->formatPattern($segment, $matches);
        $this->patterns[\count($this->segments)] = sprintf('/%s/', $pattern);
        $this->segments[] = self::DYNAMIC_SEGMENT;
    }