Matches the URI.

@param string $regex
@param string $uri
@return array|null
188476
private function matchUri(string $regex, string $uri): ?array
    {
        if (preg_match_all('/' . $regex . '/', $uri, $uriMatches)) {
            $uriMatches = array_filter($uriMatches, function ($key) {
                if (is_string($key)) {
                    return true;
                }

                return false;
            }, ARRAY_FILTER_USE_KEY);

            $uriMatches = array_map(function ($match) {
                return $match[0];
            }, $uriMatches);

            return $uriMatches;
        }

        return null;
    }
560117
public function getFolders($regex = null, $recursive = false)
    {
        //argument test
        Argument::i()
            //argument 1 must be a string
            ->test(1, 'string', 'null')
            //argument 2 must be a boolean
            ->test(2, 'bool');

        $this->absolute();

        $folders = array();

        if ($handle = opendir($this->data)) {
            //walk the directory
            while (false !== ($folder = readdir($handle))) {
                // If this is infact a directory
                //and if it matches the regex
                if ($folder != '.' && $folder != '..'
                      && filetype($this->data .'/'. $folder) == 'dir'
                    && (!$regex || preg_match($regex, $folder))) {
                    //add it
                    $folders[] = self::i($this->data . '/' . $folder);
                    if ($recursive) {
                        $subfolders = self::i($this->data.'/'.$folder);
                        $folders = array_merge($folders, $subfolders->getFolders($regex, $recursive));
                    }

                }
            }
            closedir($handle);
        }

        return $folders;
    }
877834
private function execute($regex, $data)
    {
        $matches = [];

        preg_match($regex, (string)$data, $matches);

        return $matches;
    }
610782
public function matches(string $regex): bool
    {
        if (\func_num_args() !== 1) {
            throw new LogicException('Offset is no longer supported');
        }

        return RegExp::of($regex)->matches($this);
    }
1228467
public function matches($uri, $method = null)
    {
        $uri = trim($uri, '/');
        Base::getLog()->debug(__METHOD__ . ' begin to match uri', [
            'identify' => $this->identify,
            'uri'      => $uri,
        ]);

        // 先校验URI是否正确
        if ( ! preg_match($this->routeRegex, $uri, $matches))
        {
            Base::getLog()->debug(__METHOD__ . ' route do not matched', [
                'identify' => $this->identify,
                'regex'    => $this->routeRegex,
                'uri'      => $uri,
                'method'   => $method,
            ]);
            return false;
        }

        // 解析参数
        $params = [];
        foreach ($matches as $key => $value)
        {
            if (is_int($key))
            {
                // 如果键值不是关联的话，那么就跳过
                continue;
            }
            $params[$key] = $value;
        }

        // 设置默认参数
        foreach ($this->_defaults as $key => $value)
        {
            if ( ! isset($params[$key]) || '' === $params[$key])
            {
                // 如果没匹配到，那么就设置默认值
                $params[$key] = $value;
            }
        }

        Base::getLog()->debug(__METHOD__ . ' set route params', [
            'identify' => $this->identify,
            'name'     => $uri,
            'params'   => $params,
        ]);

        // 处理method
        if (isset($params['method']) && $params['method'])
        {
            $pass = true;
            if (is_array($params['method']))
            {
                if ( ! in_array($method, $params['method']))
                {
                    $pass = false;
                }
            }
            else
            {
                if ($params['method'] != $method)
                {
                    $pass = false;
                }
            }

            if ( ! $pass)
            {
                Base::getLog()->warning(__METHOD__ . ' requested http method do not matched', [
                    'identify'       => $this->identify,
                    'uri'            => $uri,
                    'param_method'   => $params['method'],
                    'request_method' => $method,
                ]);
                return false;
            }
        }

        if ( ! empty($params['controller']))
        {
            $params['controller'] = str_replace(' ', '_', ucwords(str_replace('_', ' ', $params['controller'])));
        }

        if ( ! empty($params['directory']))
        {
            $params['directory'] = str_replace(' ', '_', ucwords(str_replace('_', ' ', $params['directory'])));
        }

        if ($this->_filters)
        {
            foreach ($this->_filters as $callback)
            {
                // 执行过滤器
                $return = call_user_func($callback, $this, $params, $uri);

                if (false === $return)
                {
                    // 停止继续匹配
                    return false;
                }
                elseif (is_array($return))
                {
                    // 修改参数值
                    $params = $return;
                }
            }
        }

        Base::getLog()->debug(__METHOD__ . ' final matched route params', [
            'identify' => $this->identify,
            'uri'      => $uri,
            'method'   => $method,
            'params'   => $params,
        ]);

        return $params;
    }
474518
protected function match($method, $uri)
    {
        $result = null;

        foreach ((array) $this->router->routes() as $route)
        {
            $matched = preg_match($route->regex(), $uri, $matches);

            if ($matched && $route->method() === $method)
            {
                return array($matches, $route);
            }
        }

        return $result;
    }
479925
private static function parseRegex($matches,$route,$regx) {
        // 获取路由地址规则
        $url   =  is_array($route)?$route[0]:$route;
        $url   =  preg_replace_callback('/:(\d+)/', function($match) use($matches){return $matches[$match[1]];}, $url); 
        if(0=== strpos($url,'/') || 0===strpos($url,'http')) { // 路由重定向跳转
            header("Location: $url", true,(is_array($route) && isset($route[1]))?$route[1]:301);
            exit;
        }else{
            // 解析路由地址
            $var  =  self::parseUrl($url);
            // 处理函数
            foreach($var as $key=>$val){
                if(strpos($val,'|')){
                    list($val,$fun) = explode('|',$val);
                    $var[$key]    =   $fun($val);
                }
            }
            // 解析剩余的URL参数
            $regx =  substr_replace($regx,'',0,strlen($matches[0]));
            if($regx) {
                preg_replace_callback('/(\w+)\/([^\/]+)/', function($match) use(&$var){
                    $var[strtolower($match[1])] = strip_tags($match[2]);
                }, $regx);
            }
            // 解析路由自动传入参数
            if(is_array($route) && isset($route[1])) {
                if(is_array($route[1])){
                    $params     =   $route[1];
                }else{
                    parse_str($route[1],$params);
                }
                $var   =   array_merge($var,$params);
            }
            $_GET   =  array_merge($var,$_GET);
        }
        return true;
    }
428803
public function match($regex = '', $true = true, $false = "")
    {
        return preg_match("~{$regex}~", $this->path) === 1 ? $true : $false;
    }
1029464
public function match($uri, $method = 'GET')
    {
        $matches = [];

        if ($this->_method !== null && $this->_method !== $method && $this->_method !== 'REST') {
            return false;
        }

        if ($this->_compiledPattern[0] !== '#') {
            if ($this->_compiledPattern === $uri) {
                return $this->_paths;
            } else {
                return false;
            }
        } else {
            $r = preg_match($this->_compiledPattern, $uri, $matches);
            if ($r === false) {
                throw new InvalidFormatException([
                    '`:compiled` pcre pattern is invalid for `:pattern`',
                    'compiled' => $this->_compiledPattern,
                    'pattern' => $this->_pattern
                ]);
            } elseif ($r === 1) {
                $parts = $this->_paths;

                foreach ($matches as $k => $v) {
                    if (is_string($k)) {
                        $parts[$k] = $v;
                    }
                }

                if ($this->_method === 'REST') {
                    if (isset($matches['params'])) {
                        $methodAction = ['GET' => 'detail', 'POST' => 'update', 'PUT' => 'update', 'DELETE' => 'delete'];
                    } else {
                        $methodAction = ['GET' => 'index', 'POST' => 'create'];
                    }
                    if (isset($methodAction[$method])) {
                        $parts['action'] = $methodAction[$method];
                    } else {
                        return false;
                    }
                }
            } else {
                return false;
            }
        }

        if (isset($parts['controller']) && $parts['controller'] === '') {
            unset($parts['controller']);
        }

        if (isset($parts['action']) && $parts['action'] === '') {
            unset($parts['action']);
        }

        $r = [];
        $r['controller'] = isset($parts['controller']) ? $parts['controller'] : 'index';
        if (isset($parts['area'])) {
            $r['area'] = $parts['area'];
        }

        $r['action'] = isset($parts['action']) ? $parts['action'] : 'index';
        $params = isset($parts['params']) ? $parts['params'] : '';

        unset($parts['area'], $parts['controller'], $parts['action'], $parts['params']);
        if ($params) {
            $parts[0] = $params;
        }
        $r['params'] = $parts;

        return $r;
    }
1318942
public function matched($uri = '', $named_params = array())
	{
		// Clean out all the non-named stuff out of $named_params
		foreach($named_params as $key => $val)
		{
			if (is_numeric($key))
			{
				unset($named_params[$key]);
			}
		}

		$this->named_params = $named_params;

		if ($this->translation instanceof \Closure)
		{
			$this->callable = $this->translation;
		}
		else
		{
			$path = $this->translation;

			if ($uri != '')
			{
				// strip the extension if needed and there is something to strip
				if ($this->strip_extension and strrchr($uri, '.') == $ext = '.'.\Input::extension())
				{
					$uri = substr($uri, 0, -(strlen($ext)));
				}

				if ($this->case_sensitive)
				{
					$path = preg_replace('#^'.$this->search.'$#uD', $this->translation, $uri);
				}
				else
				{
					$path = preg_replace('#^'.$this->search.'$#uiD', $this->translation, $uri);
				}
			}

			$this->segments = explode('/', trim($path, '/'));
		}

		return $this;
	}
65765
private function getUriParameters($uri)
    {
        $params = [];
        $pattern = '/\{([^\/]+)\}/';
        if (preg_match_all($pattern, $uri, $results) > 0) {
            foreach ($results[1] as $result) {
                $params[] = $result;
            }
        }
        return $params;
    }
789104
private static function matchesAny(array $regexes, $subject)
    {
        $matches = null;
        foreach ($regexes as $regex) {
            if ( ! in_array(preg_match("/$regex/", $subject, $matches), [0, false])) {
                return $matches;
            }
        }
    }
616157
public function match($url = null)
    {
        $match = parent::match($url);
        $regex = $this->getRegex($this->getMatchUrl());

        if ($regex !== ' ') {
            if (preg_match("@" . ltrim($regex) . "@si", $this->getRequestedUrl(), $matches) || true === $match) {
                unset($matches[0]);
                ParameterBag::setParameters($matches);
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }

    }
608795
public function match(Parser $parser, $uri, $params = array(), $strict = false)
    {
        // match literal string from start to end
        $length = strlen($this->token);
        if (substr($uri, 0, $length) === $this->token) {
            $uri = substr($uri, $length);
        }

        // when there's no match, just return null if strict mode is given
        else if ($strict) {
            return null;
        }

        return array($uri, $params);
    }
336913
public function match(string $uri): bool
    {
        if ($this->uri == $uri) {
            return true;
        }
        $pattern = '/^' . $this->regex . '$/';
        return !is_null($this->regex) && preg_match($pattern, $uri);
    }
1144496
public boolean match(String str, String regex) {
		if (str == null || regex == null)
			return false;
		if (regex.trim().isEmpty())
			return true;
		return Pattern.compile(regex.trim()).matcher(str).find();
	}
911165
public static boolean regexMatch(String input, String regex) {
        return Pattern.compile(regex).matcher(input).matches();
    }