src/Parser.php
protected static function _tokenizeSegment($pattern, $delimiter, &$variable = null)
    {
        $tokens = [];
        $index = 0;
        $path = '';

        if (preg_match_all('~' . static::PLACEHOLDER_REGEX . '()~x', $pattern, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
            foreach ($matches as $match) {
                $offset = $match[0][1];

                $path .= substr($pattern, $index, $offset - $index);
                $index = $offset + strlen($match[0][0]);

                if ($path) {
                    $tokens[] = $path;
                    $path = '';
                }

                $variable = $match[1][0];
                $capture = $match[2][0] ?: '[^' . $delimiter . ']+';

                $tokens[] = [
                    'name'      => $variable,
                    'pattern'   => $capture
                ];
            }
        }

        if ($index < strlen($pattern)) {
            $path .= substr($pattern, $index);
            if ($path) {
                $tokens[] = $path;
            }
        }
        return $tokens;
    }
protected static function _tokenizeSegment($pattern, $delimiter, &$variable = null)
    {
        $tokens = [];
        $index = 0;
        $path = '';

        if (preg_match_all('~' . static::PLACEHOLDER_REGEX . '()~x', $pattern, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
            foreach ($matches as $match) {
                $offset = $match[0][1];

                $path .= substr($pattern, $index, $offset - $index);
                $index = $offset + strlen($match[0][0]);

                if ($path) {
                    $tokens[] = $path;
                    $path = '';
                }

                $variable = $match[1][0];
                $capture = $match[2][0] ?: '[^' . $delimiter . ']+';

                $tokens[] = [
                    'name'      => $variable,
                    'pattern'   => $capture
                ];
            }
        }

        if ($index < strlen($pattern)) {
            $path .= substr($pattern, $index);
            if ($path) {
                $tokens[] = $path;
            }
        }
        return $tokens;
    }
Tokenizes segments which are patterns with optional segments filtered out.
Only classic placeholder are supported.

@param string $pattern   A route pattern with no optional segments.
@param string $delimiter The path delimiter.
@param array             An array of tokens structure.