Returns the regex needed to match the route.

@access  public
@return  string
551322
public function compileRegex()
    {
        $route = $this->route->getUri();

        if (strpos($route, '?')) {
            $route = preg_replace('@\/{([\w]+)\?}@', '(?:/{$1})?', $route);
        }

        $route = preg_replace('/{([a-z0-9_-]+)}/i', '(?P<$1>[^/]+)', $route);

        if(substr($route, -1) === '/') {
            $route .= '?';
        }

        return "%^{$route}$%s";
    }
505253
public function findRoute() {
        if (isset($_SERVER['REQUEST_URI'])) {

            $matched_uris = array();
            $routes_group = array();
            $request_uri = preg_replace('/[?]/', '', $_SERVER['REQUEST_URI']);

            foreach ($this->routes as $route) {
                if (trim(urldecode($request_uri), '/') == $route['uri']) {
                    $matched_uris[] = $route['uri'];
                    $route['args'] = [];
                    array_push($routes_group, $route);
                }
            }

            if (!$matched_uris) {
                foreach ($this->routes as $route) {
                    $route['uri'] = str_replace('/', '\/', $route['uri']);
                    $route['uri'] = preg_replace_callback('/\[(:num)(:([0-9]+))*\](\?)?/', array($this, 'findPattern'), $route['uri']);
                    $route['uri'] = preg_replace_callback('/\[(:alpha)(:([0-9]+))*\](\?)?/', array($this, 'findPattern'), $route['uri']);
                    $route['uri'] = preg_replace_callback('/\[(:any)(:([0-9]+))*\](\?)?/', array($this, 'findPattern'), $route['uri']);

                    $request_uri = parse_url($_SERVER['REQUEST_URI']);

                    preg_match("/^\/" . $route['uri'] . "$/u", urldecode($request_uri['path']), $matches);

                    if ($matches) {
                        array_push($matched_uris, $matches[0]);
                        array_shift($matches);

                        $route['args'] = $matches;
                        array_push($routes_group, $route);
                    }
                }
            }

            if (!$matched_uris) {
                self::$currentRoute = NULL;
                HookManager::call('pageNotFound');
            }

            if ($matched_uris) {
                if (count($routes_group) > 1) {

                    self::$currentModule = $routes_group[0]['module'];

                    for ($i = 0; $i < count($routes_group) - 1; $i++) {
                        for ($j = $i + 1; $j < count($routes_group); $j++) {
                            if ($routes_group[$i]['method'] == $routes_group[$j]['method']) {
                                self::$currentRoute = NULL;
                                throw new RouteException(_message(ExceptionMessages::REPETITIVE_ROUTE_SAME_METHOD, $routes_group[$j]['method']));
                                break 2;
                            }
                            if ($routes_group[$i]['module'] != $routes_group[$j]['module']) {
                                self::$currentRoute = NULL;
                                throw new RouteException(ExceptionMessages::REPETITIVE_ROUTE_DIFFERENT_MODULES);
                                break 2;
                            }
                        }
                    }

                    foreach ($routes_group as $route) {
                        if (strpos($route['method'], '|') !== false) {
                            if (in_array($_SERVER['REQUEST_METHOD'], explode('|', $route['method']))) {
                                self::$currentRoute = $route;
                                break;
                            }
                        } else if ($_SERVER['REQUEST_METHOD'] == $route['method']) {
                            self::$currentRoute = $route;
                            break;
                        }
                    }
                } else {
                    self::$currentModule = $routes_group[0]['module'];
                    self::$currentRoute = $routes_group[0];
                }
            }

            HookManager::call('handleHeaders');

            if ($_SERVER['REQUEST_METHOD'] != 'OPTIONS') {
                $this->checkMethod();
            }
        }
    }
1035361
public function parse()
    {
        $matched = [];
        foreach ($this->_routers as $router) {
            if ($router->isMatched($this->getPathInfo(), count($matched))) {
                if (defined('FOCUS_DEBUG') && FOCUS_DEBUG) {
                    $this->getLogger()->debug(sprintf('router %s is matched', get_class($router)));
                }

                $matched[] = $router;
                if ($router->isContinue() === false) {
                    break;
                }
            }
        }

        return $matched;
    }
621536
protected function getRoutes()
    {
        $c = parent::ROUTE_PATTERN_CONTROLLER;
        $a = parent::ROUTE_PATTERN_ACTION;
        $v1 = self::ROUTE_PATTERN_VERSION_ONE;
        $v2 = self::ROUTE_PATTERN_VERSION_TWO;
        $v3 = self::ROUTE_PATTERN_VERSION_THREE;
        $o = self::ROUTE_PATTERN_OBJECT_ID;
        return array(
            "/$v1/$c" => self::MATCHES_CONTROLLER,
            "/$v1/$c/" => self::MATCHES_CONTROLLER,
            "/$v2/$c" => self::MATCHES_CONTROLLER,
            "/$v2/$c/" => self::MATCHES_CONTROLLER,
            "/$v3/$c" => self::MATCHES_CONTROLLER,
            "/$v3/$c/" => self::MATCHES_CONTROLLER,
            "/$v1/$c/$a" => self::MATCHES_CONTROLLER_AND_ACTION,
            "/$v1/$c/$a/" => self::MATCHES_CONTROLLER_AND_ACTION,
            "/$v2/$c/$a" => self::MATCHES_CONTROLLER_AND_ACTION,
            "/$v2/$c/$a/" => self::MATCHES_CONTROLLER_AND_ACTION,
            "/$v3/$c/$a" => self::MATCHES_CONTROLLER_AND_ACTION,
            "/$v3/$c/$a/" => self::MATCHES_CONTROLLER_AND_ACTION,
            "/$v1/$c/$o" => self::MATCHES_CONTROLLER_AND_ID,
            "/$v1/$c/$o/" => self::MATCHES_CONTROLLER_AND_ID,
            "/$v2/$c/$o" => self::MATCHES_CONTROLLER_AND_ID,
            "/$v2/$c/$o/" => self::MATCHES_CONTROLLER_AND_ID,
            "/$v3/$c/$o" => self::MATCHES_CONTROLLER_AND_ID,
            "/$v3/$c/$o/" => self::MATCHES_CONTROLLER_AND_ID,
            "/$v1/$c/$a/$o" => self::MATCHES_CONTROLLER_ACTION_AND_ID,
            "/$v1/$c/$a/$o/" => self::MATCHES_CONTROLLER_ACTION_AND_ID,
            "/$v1/$c/$o/$a" => self::MATCHES_CONTROLLER_ACTION_AND_ID,
            "/$v1/$c/$o/$a/" => self::MATCHES_CONTROLLER_ACTION_AND_ID,
            "/$v2/$c/$a/$o" => self::MATCHES_CONTROLLER_ACTION_AND_ID,
            "/$v2/$c/$a/$o/" => self::MATCHES_CONTROLLER_ACTION_AND_ID,
            "/$v2/$c/$o/$a" => self::MATCHES_CONTROLLER_ACTION_AND_ID,
            "/$v2/$c/$o/$a/" => self::MATCHES_CONTROLLER_ACTION_AND_ID,
            "/$v3/$c/$a/$o" => self::MATCHES_CONTROLLER_ACTION_AND_ID,
            "/$v3/$c/$a/$o/" => self::MATCHES_CONTROLLER_ACTION_AND_ID,
            "/$v3/$c/$o/$a" => self::MATCHES_CONTROLLER_ACTION_AND_ID,
            "/$v3/$c/$o/$a/" => self::MATCHES_CONTROLLER_ACTION_AND_ID,
        );
    }
557662
def path_regex(self):
        """"""
        regex = r'releases/%(VERSION)s/%(PLATFORM)s/%(LOCALE)s/'
        return regex % {'LOCALE': self.locale,
                        'PLATFORM': self.platform_regex,
                        'VERSION': self.version}
624579
protected function processGroups() : string
    {
        $pattern = "";
        foreach ($this->routeGroups as $group) {
            $pattern .= $group->getPattern();
        }

        return $pattern;
    }
729114
private function match(string $url): ?array
    {
        $path = \trim(\explode('?', $url, 2)[0], self::SEPARATOR_TRIM);

        $key = $this->prefix . '_' . $path;
        $result = self::optimizeGet($key);
        if (!empty($result)) {
            return $result;
        }

        $parts = \explode('/', $path);
        if (!isset($parts[1]) && $parts[0] === '') {
            $parts = [];
        }

        $params = [];
        $current = $this->routes;
        foreach ($parts as $v) {
            if (isset($current['children'][$v])) {
                $current = $current['children'][$v];
                continue;
            }

            if ($current['regexps'] !== []) {
                foreach ($current['regexps'] as $regexp => $route) {
                    if (\preg_match($regexp, $v)) {
                        $current = $route;
                        $params[$current['name']] = $v;
                        continue 2;
                    }
                }
            }

            if (!isset($current['others'])) {
                return null;
            }

            $current = $current['others'];
            $params[$current['name']] = $v;
        }

        $result = [
            'methods' => $current['methods'],
            'route' => $current['route'],
            'params' => $params,
        ];

        self::optimizeSet($key, $result);

        return $result;
    }
363536
protected function _compile_regex($route)
    {
        $pattern = '`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`';

        if ( preg_match_all($pattern, $route, $matches, PREG_SET_ORDER) ) {
            $match_types = array(
                'i'  => '[0-9]++',
                'a'  => '[0-9A-Za-z]++',
                'h'  => '[0-9A-Fa-f]++',
                '*'  => '.+?',
                ''   => '[^/]++'
            );
            foreach ( $matches as $match ) {
                list($block, $pre, $type, $param, $optional) = $match;

                if ( isset($match_types[$type]) ) {
                    $type = $match_types[$type];
                }
                if ( $param ) {
                    $param = "?<{$param}>";
                }
                if ( $optional ) {
                    $optional = '?';
                }

                $replaced = "(?:{$pre}({$param}{$type})){$optional}";
                $route = str_replace($block, $replaced, $route);
            }
        }
        if ( substr($route, strlen($route) - 1) != '/' ) {
            $route .= '/?';
        }
        return "`^{$route}$`";
    }
1262431
private function match(string $url, Route $route) : array
    {
        $regexp = $this->routeRegexp($route);

        if (preg_match_all('`^' . $regexp . '$`', $url, $matches, PREG_SET_ORDER)) {
            // remove all numeric matches
            $matches = array_diff_key($matches[0], range(0, count($matches[0])));

            // control query string
            if ($route->getUserInputs()) {
                foreach ($route->getUserInputs() as $querystring) {
                    $method = self::request()->getMethod() == 'POST' ? 'getPostOrQuery' : 'getQuery';
                    $value = self::request()->$method($querystring->getName(), $querystring->getType());

                    if (is_null($value) && $querystring->isMandatory()) {
                        return [false, null, $regexp];
                    }

                    if (!is_null($value)) {
                        $matches[$querystring->getName()] = $value;
                    }
                }
            }

            // control conditions
            if ($route->getConditions()) {
                foreach ($route->getConditions() as $condition) {
                    if (!$condition($matches)) {
                        return [false, null, $regexp];
                    }
                }
            }

            return [true, $matches, $regexp];
        }

        return [false, null, $regexp];
    }
363029
protected function getRegexes()
    {
        if (empty($this->regexList)) {
            $cacheKey = 'DeviceDetector-'.DeviceDetector::VERSION.'regexes-'.$this->getName();
            $cacheKey = preg_replace('/([^a-z0-9_-]+)/i', '', $cacheKey);
            $this->regexList = $this->getCache()->fetch($cacheKey);
            if (empty($this->regexList)) {
                $this->regexList = $this->getYamlParser()->parseFile(
                    $this->getRegexesDirectory().DIRECTORY_SEPARATOR.$this->fixtureFile
                );
                $this->getCache()->save($cacheKey, $this->regexList);
            }
        }
        return $this->regexList;
    }
34581
public function getRoute()
    {
        $route = substr($this->route, strlen($this->prefix));
        // Stripping final '/'.
        if(strlen($route) > 1
           && $route[strlen($route) - 1] == '/') {
            $route = substr($route, 0, strlen($route) - 1);
        }

        return $route;
    }
324417
protected function guessGuard(): string
    {
        $accessarea = str_before(Route::currentRouteName(), '.');
        $guard = str_plural(mb_strstr($accessarea, 'area', true));

        return config('auth.guards.'.$guard) ? $guard : config('auth.defaults.guard');
    }
279326
private function assembleRouteName() : string
    {
        $prefix = ($this->secure) ? 'secure-api' : 'api';

        $routeName = 'resource';

        if ($this->relatedId !== null) {
            $routeName = 'resource.relationship.item';
        } else {
            if ($this->relationship !== null) {
                $routeName = 'resource.relationship';
            } else {
                if ($this->id !== null) {
                    $routeName = 'resource.item';
                }
            }
        }

        return $prefix . '.' . $routeName;
    }
606532
public function getCurrentRouteMatch() {
    if (empty($this->currentRouteMatch)) {
      $this->currentRouteMatch = \Drupal::service('current_route_match');
    }
    return $this->currentRouteMatch;
  }
336945
public function matches(Route $route, Request $request)
    {
        $path = $request->path() === '/' ? '/' : '/'.$request->path();

        return preg_match($route->getCompiled()->getRegex(), rawurldecode($path));
    }
651452
public function matchPath($regexp)
	{
		if (substr($regexp, 0, 1) == '@') {
			$this->route_name = substr($regexp, 1);
		} else {
			parent::matchPath($regexp);
		}
	}
786900
public function matchRoute($route, Route $routeItem)
    {
        $regex = $routeItem->getRegex();

        if (!$regex || $this->debug) {
            $regex = BasicCompiler::compile($routeItem->getPattern(), $routeItem->getRequirements());

            $routeItem->setRegex($regex);
        }

        $route = RouteHelper::normalise($route);

        if (preg_match($regex, $route, $matches)) {
            $variables = RouteHelper::getVariables($matches);

            $variables['_rawRoute'] = $route;
        } else {
            return false;
        }

        $routeItem->setVariables(array_merge($routeItem->getVariables(), $variables));

        return $routeItem;
    }