protected function buildRegexp($pattern, array $matches)
    {
        $src = [];
        $trg = [];
        foreach ($matches as $match) {
            list($key, $regexp) = $this->splitSegment($match[3]);

            if (in_array(substr($regexp, -1), ['+', '*', '?'])) {
                throw new RouteException('Route must not end with quantification token');
            }

            $src[rtrim($match[0], '/')] = $key;

            $trg[$key] = '(?P<' . $key . '>' . $regexp . '+)';

            if ($match[1] == '(') {
                $trg[$key] = '(' . $trg[$key] . $this->buildConditionalSlash(preg_quote($match[4], '/')) . ')?';
            }
        }

        $pattern = strtr($pattern, $src);
        $pattern = preg_quote($pattern, '/');
        $pattern = strtr($pattern, $trg);
        $pattern = str_replace('\/((?P', '\/?((?P', $pattern);
        $pattern = $this->buildConditionalSlash($pattern);

        return '/^' . $pattern . '$/i';
    }
protected function buildRegexp($pattern, array $matches)
    {
        $src = [];
        $trg = [];
        foreach ($matches as $match) {
            list($key, $regexp) = $this->splitSegment($match[3]);

            if (in_array(substr($regexp, -1), ['+', '*', '?'])) {
                throw new RouteException('Route must not end with quantification token');
            }

            $src[rtrim($match[0], '/')] = $key;

            $trg[$key] = '(?P<' . $key . '>' . $regexp . '+)';

            if ($match[1] == '(') {
                $trg[$key] = '(' . $trg[$key] . $this->buildConditionalSlash(preg_quote($match[4], '/')) . ')?';
            }
        }

        $pattern = strtr($pattern, $src);
        $pattern = preg_quote($pattern, '/');
        $pattern = strtr($pattern, $trg);
        $pattern = str_replace('\/((?P', '\/?((?P', $pattern);
        $pattern = $this->buildConditionalSlash($pattern);

        return '/^' . $pattern . '$/i';
    }
protected function buildRegexp ( $ pattern , array $ matches ) { $ src = [ ] ; $ trg = [ ] ; foreach ( $ matches as $ match ) { list ( $ key , $ regexp ) = $ this -> splitSegment ( $ match [ 3 ] ) ; if ( in_array ( substr ( $ regexp , - 1 ) , [ '+' , '*' , '?' ] ) ) { throw new RouteException ( 'Route must not end with quantification token' ) ; } $ src [ rtrim ( $ match [ 0 ] , '/' ) ] = $ key ; $ trg [ $ key ] = '(?P<' . $ key . '>' . $ regexp . '+)' ; if ( $ match [ 1 ] == '(' ) { $ trg [ $ key ] = '(' . $ trg [ $ key ] . $ this -> buildConditionalSlash ( preg_quote ( $ match [ 4 ] , '/' ) ) . ')?' ; } } $ pattern = strtr ( $ pattern , $ src ) ; $ pattern = preg_quote ( $ pattern , '/' ) ; $ pattern = strtr ( $ pattern , $ trg ) ; $ pattern = str_replace ( '\/((?P' , '\/?((?P' , $ pattern ) ; $ pattern = $ this -> buildConditionalSlash ( $ pattern ) ; return '/^' . $ pattern . '$/i' ; }
Builds regular expression for route matching

@param string $pattern
@param array  $matches

@return string
@throws RouteException
Builds regular expression for route matching