检查传递的字符串是否与给定的通配符模式匹配.
@param string $pattern 通配符.
@param string $string 字符串.
@param array $options 用于匹配的选项.
@param   bool $caseSensitive 是否区分大小写，默认为'true'.
@param   bool $escape 反斜杠是否转义，默认为'true'.
@param   bool $filePath 斜线是否匹配，默认为'false'.
@return bool
7584
public static function matchWildcard(
        string $pattern,
        string $string,
        array $options = []
    ): bool {
        if ($pattern === '*' && empty($options['filePath'])) {
            return true;
        }

        $replacements = [
            '\\\\\\\\' => '\\\\',
            '\\\\\\*' => '[*]',
            '\\\\\\?' => '[?]',
            '\*' => '.*',
            '\?' => '.',
            '\[\!' => '[^',
            '\[' => '[',
            '\]' => ']',
            '\-' => '-',
        ];

        if (isset($options['escape']) && !$options['escape']) {
            unset($replacements['\\\\\\\\']);
            unset($replacements['\\\\\\*']);
            unset($replacements['\\\\\\?']);
        }

        if (!empty($options['filePath'])) {
            $replacements['\*'] = '[^/\\\\]*';
            $replacements['\?'] = '[^/\\\\]';
        }

        $pattern = strtr(preg_quote($pattern, '#'), $replacements);
        $pattern = '#^' . $pattern . '$#us';

        if (isset($options['caseSensitive']) && !$options['caseSensitive']) {
            $pattern .= 'i';
        }

        return preg_match($pattern, $string) === 1;
    }
1229864
public static boolean safeRegexMatch(String pattern, String value) {
        if (StringUtils.isNotBlank(pattern)) {
            if (value == null) {
                return false;
            } else {
                try {
                    return Pattern.matches(pattern, value);
                } catch (PatternSyntaxException ex) {
                    return false;
                }
            }
        } else {
            return false;
        }
    }
656322
public boolean checkRegexPattern(final Optional<Subject> subjectOption,
                                     final Optional<Pattern> patternOption)
    {
        final boolean[] roleOk = {false};
        subjectOption.ifPresent(subject -> patternOption.ifPresent(pattern -> {
            final List<? extends Permission> permissions = subject.getPermissions();
            if (permissions != null)
            {
                for (Iterator<? extends Permission> iterator = permissions.iterator(); !roleOk[0] && iterator.hasNext(); )
                {
                    final Permission permission = iterator.next();
                    roleOk[0] = pattern.matcher(permission.getValue()).matches();
                }
            }
        }));

        return roleOk[0];
    }
929992
public function trimLeft( $string, $needle, $caseSensitive = true )
	{
		$strPos = $caseSensitive ? "strpos" : "stripos";
		if( $strPos( $string, $needle ) === 0 ) {
			$string = substr( $string, strlen( $needle ));
		}
		return $string;
	}
107529
public static function transpilePattern($pattern, $host = false, array $requirements = [], array $defaults = [])
    {
        $tokens = self::tokenizePattern($pattern, $host, $requirements, $defaults);

        $staticPath = !$tokens[0] instanceof Variable ? $tokens[0]->value : '/';

        $regex = self::transpileMatchRegex($tokens);

        return self::getCompact($staticPath, $regex, $tokens);
    }
402902
public function get($uri, $pattern, array $options = [])
    {
        $options = array_merge($options, $this->filter);

        if (is_callable($pattern)) {
            $this->route->add('GET', $this->prefix . $uri, $pattern, $options);
        } else {
            $this->route->add('GET', $this->prefix . $uri, $this->namespace . $pattern, $options);
        }
    }
61554
public static boolean match(String filePath, String patternPath) {
    return match(new AlluxioURI(filePath), new AlluxioURI(patternPath));
  }
808697
public function compare($compare, $caseSensitive = true)
    {
        if ($caseSensitive) {
            return Mbstring::strcmp($this->string, $compare);
        }

        return Mbstring::strcasecmp($this->string, $compare, $this->encoding);
    }
1071452
public static Query regex(String field,
                              String pattern,
                              boolean caseInsensitive,
                              boolean extended,
                              boolean multiline,
                              boolean dotall) {
        Query q = new Query(false);
        q.add("field", field).add("regex", pattern).
                add("caseInsensitive", caseInsensitive).
                add("extended", extended).
                add("multiline", multiline).
                add("dotall", dotall);
        return q;
    }
921747
static function endsWith($string, $endsWith, $caseSensitive = true) {
		$len = self::strlen($endsWith);
		if ($caseSensitive) return self::substr($string, -1 * $len) == $endsWith;
		return self::strtolower(self::substr($string, -1 * $len)) == self::strtolower($endsWith);
	}
146737
public function whenAssetIs($pattern)
    {
        return $this->when(function($asset) use ($pattern)
        {
            return (bool) preg_match('#'.$pattern.'#', $asset->getRelativePath());
        });
    }
678479
public function filter($value, $options = [])
    {
        if ($this->getPattern() == null) {
            $ex = new \Exception(get_class($this) . ' does not have a valid MatchPattern set.');
            throw $ex;
        }

        return preg_replace($this->getPattern(), $this->getReplacement(), $value);
    }
54984
protected function filterPath($path, $pattern, array $extensions=[])
    {
        $usePattern = $this->isFilterPattern($pattern);

        if (!$usePattern && !$extensions) {
            return true;
        }

        if ($usePattern && !fnmatch($pattern, $this->basename($path))) {
            return false;
        }

        if ($extensions && !in_array(strtolower($this->extension($path)), $extensions)) {
            return false;
        }

        return true;
    }
520047
static function compilePattern($pattern, array $options = array())
    {

        $len = strlen($pattern);
        /**
         * contains:
         *
         *   array( 'text', $text ),
         *   array( 'variable', $match[0][0][0], $regexp, $var);
         *
         */
        $tokens = array();
        $variables = array();
        $pos = 0;

        /**
         *  the path like:
         *
         *      /blog/to/:year/:month
         *
         *  will be separated like:
         *      
         *      [
         *          '/blog/to',  (text token)
         *          '/:year',    (reg exp token)
         *          '/:month',   (reg exp token)
         *      ]
         */
        $matches = self::splitTokens($pattern);


        // build tokens
        foreach ($matches as $matchIdx => $match) {
            // match[0][1] // matched position for pattern.

            /*
             * Split tokens from abstract pattern
             * to rebuild regexp pattern.
             */
            if ($text = substr($pattern, $pos, $match[0][1] - $pos)) {
                $tokens[] = array( self::TOKEN_TYPE_TEXT, $text);
            }

            // the first char from pattern (which is the seperater)
            // and the first char from the next match pattern
            $seps = array($pattern[$pos]);


            // collect the separator tokens from the next matched pattern
            if (isset($matches[$matchIdx + 1])) {
                $nextMatch = $matches[$matchIdx + 1];

                // check if the next pattern is an optional pattern
                if ($nextMatch[0][0][0] === '(') {

                    $r = self::compilePattern($nextMatch[2][0] ,array());
                    if (isset($r['tokens'][0][1])) {
                        $seps[] = $r['tokens'][0][1][0];
                    }

                } else if ($nextMatch[0][0][0] === ':') { // variable token

                } else {
                    $seps[] = $nextMatch[0][0][0];
                }
            }


            $pos = $match[0][1] + strlen($match[0][0]);


            // generate optional pattern recursively
            if ($match[0][0][0] == '(' ){
                $optional = $match[2][0];
                $subroute = self::compilePattern($optional ,array(
                    'default'   => isset($options['default']) ? $options['default'] : null,
                    'require'   => isset($options['require']) ? $options['require'] : null,
                    'variables' => isset($options['variables']) ? $options['variables'] : null,
                ));

                $tokens[] = array( 
                    self::TOKEN_TYPE_OPTIONAL,
                    $optional[0],
                    $subroute['regex'],
                );
                foreach( $subroute['variables'] as $var ) {
                    $variables[] = $var;
                }
            } else {
                // generate a variable token 
                $varName = $match[1][0];

                // if we defined a pattern for this variable, we should use the given pattern..
                if ( isset( $options['require'][$varName] ) && $req = $options['require'][$varName]) {
                    $regexp = $req;
                } else {
                    if ($pos !== $len) {
                        $seps[] = $pattern[$pos];
                    }
                    // use the default pattern (which is based on the separater charactors we got)
                    $regexp = sprintf('[^%s]+', preg_quote(implode('', array_unique($seps)), '#'));
                }

                // append token item
                $tokens[] = array(self::TOKEN_TYPE_VARIABLE, 
                    $match[0][0][0], 
                    $regexp, 
                    $varName);

                // append variable name
                $variables[] = $varName;
            }
        }

        if ($pos < $len) {
            $tokens[] = array(self::TOKEN_TYPE_TEXT, substr($pattern, $pos));
        }

        // find the first optional token
        $firstOptional = INF;
        for ($i = count($tokens) - 1; $i >= 0; $i--) {
            if ( self::TOKEN_TYPE_VARIABLE === $tokens[$i][0] 
                && isset($options['default'][ $tokens[$i][3] ]) )
            {
                $firstOptional = $i;
            } 
            else 
            {
                break;
            }
        }

        // compute the matching regexp
        $regex = '';

        // indentation level
        $indent = 1;


        // token item structure:
        //   [0] => token type,
        //   [1] => separator
        //   [2] => pattern
        //   [3] => name, 

        // first optional token and only one token.
        if (1 === count($tokens) && 0 === $firstOptional) {
            $token = $tokens[0];
            ++$indent;

            // output regexp with separator and
            $regex .= str_repeat(' ', $indent * 4) . sprintf("%s(?:\n", preg_quote($token[1], '#'));

            // regular expression with place holder name. (?P<name>pattern)
            $regex .= str_repeat(' ', $indent * 4) . sprintf("(?P<%s>%s)\n", $token[3], $token[2]);

        } else {
            foreach ($tokens as $i => $token) {

                switch ( $token[0] ) {
                case self::TOKEN_TYPE_TEXT:
                    $regex .= str_repeat(' ', $indent * 4) . preg_quote($token[1], '#')."\n";
                    break;
                case self::TOKEN_TYPE_OPTIONAL:
                    // the question mark is for optional, the optional item may contains multiple tokens and patterns
                    $regex .= str_repeat(' ', $indent * 4) . "(?:\n" . $token[2] . str_repeat(' ', $indent * 4) . ")?\n";
                    break;
                default:
                    // append new pattern group for the optional pattern
                    if ($i >= $firstOptional) {
                        $regex .= str_repeat(' ', $indent * 4) . "(?:\n";
                        ++$indent;
                    }
                    $regex .= str_repeat(' ', $indent * 4). sprintf("%s(?P<%s>%s)\n", preg_quote($token[1], '#'), $token[3], $token[2]);
                    break;
                }
            }
        }

        // close groups
        while (--$indent) {
            $regex .= str_repeat(' ', $indent * 4).")?\n";
        }

        // save variables
        $options['variables'] = $variables;
        $options['regex'] = $regex;
        $options['tokens'] = $tokens;
        return $options;
    }
171188
public function validate(string $input, bool $caseSensitive): bool
    {
        $code = $this->getVerifyCode();
        $valid = $caseSensitive ? ($input === $code) : strcasecmp($input, $code) === 0;
        $session = $this->getApp()->getSession();
        $session->open();
        $name = $this->getSessionKey() . 'count';
        $session[$name] += 1;
        if ($valid || $session[$name] > $this->testLimit && $this->testLimit > 0) {
            $this->getVerifyCode(true);
        }

        return $valid;
    }
1354710
public static function start_with($string, $needle, $case_sensitive = true)
    {
        if(!is_string($string))
        {
            $string = (string)$string;
        }
        
        if(!is_string($needle))
        {
            $needle = (string)$needle;
        }
        
        if($case_sensitive)
        {
            return strpos($string, $needle) === 0;
        }
        else
        {
            return stripos($string, $needle) === 0;
        }
    }
1287145
public static function checkPatternMatchFileList($fileList, $pattern){
		foreach ($fileList as $filename) {
			if(self::checkFilePattern($filename, $pattern))
				return true;
		}
		return false;
	}