Pattern Matching. Use switch-case for explicit values, this for everything else.
@param array $patterns
@return mixed
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;
        };
    }
924856
public function match($pattern)
    {
        if (!is_string($pattern)) {
            throw new InvalidStringException('pattern', $pattern);
        } elseif (empty($pattern)) {
            throw new InvalidNotEmptyException('pattern');
        }

        if (!is_string($this->value)) {
            throw new InvalidStringException($this->name, $this->value);
        }

        // God please sorry for this @
        $checkResult = @preg_match($pattern, $this->value);

        if ((preg_last_error() !== PREG_NO_ERROR) || ($checkResult === false)) {
            throw new InvalidRegExpPatternException('pattern', $pattern);
        }

        if ($checkResult === 0) {
            throw new StringNotMatchRegExpException($this->name, $this->value, $pattern);
        }

        return $this;
    }
683225
public function match($patterns)
    {
        if (!is_array($patterns)) {
            $patterns = [$patterns];
        }

        $url = $this->getUrl();

        foreach ($patterns as $pattern) {
            $pattern = str_replace(['\\*', '\\?'], ['.+', '?'], preg_quote($pattern, '|'));

            if (preg_match('|^'.$pattern.'$|i', $url)) {
                return true;
            }
        }

        return false;
    }
82001
public function matchPattern(string $pattern) : Element
    {
        $this->attributes['pattern'] = $pattern;
        return $this->addTest('pattern', function ($value) use ($pattern) {
            return preg_match("@^$pattern$@", trim($value));
        });
    }
1203295
protected function processPattern(array $patterns)/*# : array */
    {
        $result = [];
        foreach ($patterns as $pat) {
            $part = explode('/', $pat);
            $addr = ip2long($part[0]);
            $mask = isset($part[1]) ? ((int) $part[1]) : 32;

            // fix
            $mask = $this->getMask($mask);
            $addr = $addr & $mask;

            $result[] = [$addr, $mask];
        }
        return $result;
    }
227526
public function match($pattern, $path, array $patterns = []) {
        $patterns = $this->mergeWithLocalPatterns($patterns);

        $path = $this->addTrailingSlash($path);
        $pattern = $this->createRegexPattern($pattern, $patterns);
        $matches = [];

        if (preg_match_all($pattern, $path, $matches) === 1) {
            $matchedPath = $this->addTrailingSlash(array_get($matches, '0.0'));

            return $matchedPath == $path;
        };

        return false;
    }
747265
public function grep($pattern)
    {
        $results = array_intersect_key($this->attributes, array_flip(
            RegexGuard::getGuard()->grep($pattern, array_keys($this->attributes))
        ));

        return new static($results);
    }
1095056
protected function convertPattern($pattern)
    {
        $prefix = 0 === strpos($pattern, '!') ? '!' : '';
        $searchPattern = trim(ltrim($pattern, '!'), '/');
        $pattern = $prefix.$searchPattern;

        if (\in_array($searchPattern, array('*', '*.*'), true)) {
            $this->doAddPattern($prefix.'.*');
        } elseif (0 === strpos($searchPattern, '**/')) {
            $this->doAddPattern($prefix.'**/'.$searchPattern);
            $this->doAddPattern($prefix.substr($searchPattern, 3));
        } else {
            $this->convertPatternStep2($prefix, $searchPattern, $pattern);
        }

        return $pattern;
    }
447516
public function pattern($pattern = null)
        {
            if ($pattern === null) return $this->rulePattern;

            $this->rulePattern = $pattern;

            return $this;
        }
665527
public function grep($values, $pattern, $flags = '')
    {
        if (!isset($values)) {
            return null;
        }
        
        if (is_string($flags)) {
            $flags = $flags === 'invert' ? PREG_GREP_INVERT : 0;
        }
        
        return preg_grep($pattern, $values, $flags);
    }
1295581
private function checkPatterns($value, array $patterns)
    {
        foreach ($patterns as $pattern) {
            if (Str::is($pattern, $value)) return true;
        }

        return false;
    }
186354
public function getKeys($pattern = null)
    {
        $keys = $this->get('__stored_keys__', []);
        if (is_null($pattern)) {
            return $keys;
        }

        $matches = [];
        $pattern = $this->_normalizePattern($pattern);
        foreach ($keys as $key) {
            if (preg_match($pattern, $key)) {
                $matches[] = $key;
            }
        }

        return $matches;
    }
401494
public function matches($pattern)
    {
        $this->isString();

        $this->doCheck(function ($value) use ($pattern) {
            $this->throwExceptionIfFalse(
                preg_match($pattern, $value),
                'String "%s" does not match "%s"', $value, $pattern
            );
        });

        return $this;
    }
996723
public function match($patterns)
    {
        if (!is_array($patterns)) {
            $patterns = [$patterns];
        }

        //Remove scheme and query
        $long_url = preg_replace('|^(\w+://)|', '', (string) $this);
        $short_url = preg_replace('|(\?.*)?$|', '', $long_url);

        foreach ($patterns as $pattern) {
            if ($pattern[0] === '?') { // ?hello=world => *?hello=world
                $pattern = '*' . $pattern;
            }

            $pattern = str_replace('\\*', '.*', preg_quote($pattern, '|'));

            if (strpos($pattern, '?') === false) {
                $url = $short_url;
            } else {
                $pattern = str_replace('\\?&', '[\\?&]', $pattern);
                $url = $long_url;
            }

            if (preg_match('|^'.$pattern.'$|i', $url)) {
                return true;
            }
        }

        return false;
    }
1185729
public function matchUrl($pattern)
    {
        if ($this->matchValue($this->getUrl(), $pattern)) {
            return $this->getUrl();
        }

        return false;
    }
1018146
protected static function transform(Pattern $pattern) {
        $result = [];
        $groups = [[$pattern]];

        while ($groups) {
            $children = array_shift($groups);
            $hasBranchPattern = false;
            foreach ($children as $c) {
                if ($c instanceof BranchPattern) {
                    $hasBranchPattern = true;
                    break;
                }
            }
            if ($hasBranchPattern) {
                /** @var BranchPattern $child */
                $child = null;
                foreach ($children as $key => $currentChild) {
                    if ($currentChild instanceof BranchPattern) {
                        $child = $currentChild;
                        unset($children[$key]);
                        break;
                    }
                }
                if ($child instanceof Either) {
                    foreach ($child->children as $c) {
                        $groups[] = array_merge([$c], $children);
                    }
                }
                else if ($child instanceof OneOrMore) {
                    $groups[] = array_merge($child->children, $child->children, $children);
                }
                else {
                    $groups[] = array_merge($child->children, $children);
                }
            }
            else {
                $result[] = $children;
            }
        }

        $rs = [];
        foreach ($result as $e) {
            $rs[] = new Required($e);
        }
        return new Either($rs);
    }
238144
public function filterChangedProperties(string $pattern) : array
    {
        return array_filter($this->changedProperties, function ($key) use ($pattern) {
            return preg_match($pattern, $key) > 0;
        }, ARRAY_FILTER_USE_KEY);
    }