@param string $pattern
@param array $patterns

@return bool
490085
public function match($pattern, array $patterns = []) {
        return $this->matcher->match(
            $this->addLeadingSlash($pattern), $this->getPath(), $patterns
        );
    }
364263
public static function filterArrayValuesWithPattern(array $values, $pattern)
    {
        return array_values(
            array_filter(
                array_map(function ($key) use ($pattern) {
                    if ((bool) preg_match('/'.$pattern.'/', $key)) {
                        return $key;
                    }
                }, $values)
            )
        );
    }
1071178
public function matches($name, $pattern, &$matches = []) {
		return preg_match($pattern, $this->get($name), $matches);
	}
447516
public function pattern($pattern = null)
        {
            if ($pattern === null) return $this->rulePattern;

            $this->rulePattern = $pattern;

            return $this;
        }
204433
private function isValidPattern(string $pattern): bool
    {
        set_error_handler(function (int $severity, string $message, string $file, int $line): bool {
            throw new \ErrorException($message, 0, $severity, $file, $line);
        }, \E_ALL);

        try {
            $result = preg_match("/$pattern/", '');
        } catch (\ErrorException $exception) {
            $errorMessage = sprintf("Invalid regular expression '%s': %s", $pattern, $exception->getMessage());
            throw new \InvalidArgumentException($errorMessage, 0, $exception);
        } finally {
            restore_error_handler();
        }

        return $result !== false;
    }
159022
public function setPatterns(array $patterns)
    {
        $patternValues = implode("", $patterns);
        if (mb_strlen($patternValues) < strlen($patternValues)) {
            $this->options['multibytePattern'] = true;
        }
        $this->options = array_merge($this->options, $patterns);

        return $this;
    }
552139
protected static function __match(array $patterns)
    {
        return function (...$args) use ($patterns) {
            $parameterTypes = array_map(self::getType(), $args);

            try {
                $keysToValues = Arrays::zip(array_keys($patterns), array_values($patterns));

                list($key, $matchingPattern) = Arrays::first(
                    Pattern::patternApplies($parameterTypes, $args),
                    $keysToValues
                );
            } catch (ElementNotFoundException $e) {
                throw new IncompletePatternMatchException(
                    'Incomplete pattern match expression. (missing ' . implode(', ', $parameterTypes) . ')'
                );
            }


            /**
             * Upcoming Feature, Array DSL for matching via `x::xs` etc.
             */
//            // if key is a string, manually match
//            if (is_string($key)) {
//
//                throw new \Exception('Array DSL not available.');
//            }

            list($hasExtractable, $unwrappedArgs) = self::unwrapArgs($args);

            $value = $matchingPattern(...$args);
            $isCallable = is_callable($value);

            if ($hasExtractable && ! $isCallable) {
                throw new InvalidPatternMatchException(
                    'Invalid pattern match expression. (one of ' . implode(', ', $parameterTypes)
                    . ' requires a callback to unwrap)'
                );
            }

            /**
             * Extractable requires a callback to feed args into.
             */
            if ($hasExtractable && $isCallable) {
                return $matchingPattern(...$args)(...$unwrappedArgs);
            }

            /**
             * No extractable so we can just return the value directly.
             */
            return $value;
        };
    }
1287145
public static function checkPatternMatchFileList($fileList, $pattern){
		foreach ($fileList as $filename) {
			if(self::checkFilePattern($filename, $pattern))
				return true;
		}
		return false;
	}
770457
public function is(...$patterns)
    {
        $path = $this->decodedPath();

        foreach ($patterns as $pattern) {
            if (Str::is($pattern, $path)) {
                return true;
            }
        }

        return false;
    }
27371
protected function applyCustomRegexPatterns($path, array $patterns) {
        foreach ($patterns as $pattern) {
            $path = preg_replace([$pattern->getRegexName()], $pattern->getRegexPattern(), $path);
        }

        return $path;
    }
1061265
protected function _requestMatches($patterns)
    {
        if (empty($patterns)) {
            return false;
        }

        $request = $this->_View->request;
        $path = '/' . urldecode($request->url);
        $patterns = explode("\n", $patterns);

        foreach ($patterns as &$p) {
            $p = $this->_View->Url->build('/') . $p;
            $p = str_replace('//', '/', $p);
            $p = str_replace($request->base, '', $p);
            $p = $this->localePrefix($p);
        }

        $patterns = implode("\n", $patterns);

        // Convert path settings to a regular expression.
        // Therefore replace newlines with a logical or, /* with asterisks and "/" with the front page.
        $toReplace = [
            '/(\r\n?|\n)/', // newlines
            '/\\\\\*/', // asterisks
            '/(^|\|)\/($|\|)/' // front '/'
        ];

        $replacements = [
            '|',
            '.*',
            '\1' . preg_quote($this->_View->Url->build('/'), '/') . '\2'
        ];

        $patternsQuoted = preg_quote($patterns, '/');
        $patterns = '/^(' . preg_replace($toReplace, $replacements, $patternsQuoted) . ')$/';

        return (bool)preg_match($patterns, $path);
    }
802677
public function matchHost($pattern, &$matches = null, $flags = 0, $offset = 0)
	{
		return preg_match($pattern, $this->_host ?: '', $matches, $flags, $offset);
	}
1185729
public function matchUrl($pattern)
    {
        if ($this->matchValue($this->getUrl(), $pattern)) {
            return $this->getUrl();
        }

        return false;
    }
798345
protected static function key_matcher(array $pattern)
    {
        $keys = [];
        foreach ($pattern as $k => $v) {
            $chars = ['?' => [0, 1], '*' => [0, PHP_INT_MAX], '!' => [1, 1]];
            if (isset($chars[$last = substr($k, -1)])) {
                $keys[$k = substr($k, 0, -1)] = $chars[$last];
            } elseif ($last == '}') {
                list($k, $range) = explode('{', $k);
                $range = explode(',', rtrim($range, '}'));
                $keys[$k] = count($range) == 1
                    ? [$range[0], $range[0]]
                    : [$range[0] === '' ? 0 : $range[0], $range[1] === '' ? PHP_INT_MAX : $range[1]];
            } else {
                $keys[$k] = $chars[$k[0] == ':' ? '*' : '!'];
            }
            array_push($keys[$k], $v, 0);
        }

        return function ($key = null, $value = null) use (&$keys) {
            if (is_null($key)) foreach ($keys as $count) {
                if ($count[3] < $count[0] || $count[3] > $count[1]) return false;
            } else foreach ($keys as $k => &$count) if (self::matcher($key, $k)) {
                if (!self::matches($value, $count[2])) return false;
                $count[3]++;
            }
            return true;
        };
    }
764707
public function checkUrlMatch($pattern, $url)
    {
        $url = trim($url, '/');
        if (!$url) {
            $url = '/';
        }
        $matcher = $this->getPatternRegexp($pattern);
        if (preg_match($matcher, $url, $matches)) {
            return true;
        }
        return false;
    }
189612
public function named(...$patterns)
    {
        if (is_null($routeName = $this->getName())) {
            return false;
        }

        foreach ($patterns as $pattern) {
            if (Str::is($pattern, $routeName)) {
                return true;
            }
        }

        return false;
    }
714034
public function addPatterns($patterns)
    {
        foreach ($patterns as $name => $pattern) {
            $this->addPattern($name, $pattern);
        }

        return $this;
    }