Returns whether a string matches against a wildcard pattern.

May use * and ? wildcards.

@param string $source
@param string $pattern
@return bool
499962
protected function wildCardMatch($source, $pattern)
    {
        $pattern = preg_quote($pattern, '#');

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

        return (bool) preg_match('#^' . $pattern . '$#i' , $source);
    }
1304999
protected function getMatches($source)
    {
        if ($this->hasMatches($source)) {
            preg_match_all($this->pattern, $source, $matches, PREG_SET_ORDER);

            return $matches;
        }
    }
878166
private static boolean check(String data, Pattern pattern) {
        if (StringUtils.isEmpty(data)) {
            return false;
        }
        Matcher matcher = pattern.matcher(data);
        return matcher.matches();
    }
1159647
public function getMatchAll(string $pattern, int $flags = PREG_PATTERN_ORDER, int $offset = 0)
	{
		return preg_match_all($pattern, $this->str, $matches, $flags, $offset) === false ? null : $matches;
	}
263673
public function parsePoSource(string $source): void
    {
        /**
         * This is an incredibly ugly regex pattern that breaks a line of a po file into
         * pieces that can be analyzed and acted upon.
         *
         * The matches array in preg_match will break out like this:
         *  [0] full string
         *  [1] mostly useless broad match of initial token, including trailing space
         *  [2] bare token, or full msgstr[n] clause
         *  [3] 'n' of a msgstr[n] line
         *  [4] '"' if a data line
         *  [5] remaining line
         *  [6] a bare or malformed comment
         */
        $pattern = '/(^(#|#.|#;|#,|#\||msgid|msgid_plural|msgctxt|msgstr|msgstr\[([0-9]+)\])\s|(^"))(.+)|(^#.*)/';

        $source_lines = explode("\n", $source);

        $wsBreak = false;
        $inHeader = true;
        $headerEntry = new PoHeader;
        $entry = $headerEntry;
        $unrecognized = array();
        $lastKey = '';
        $currentPlural = 0;
        foreach ($source_lines as $line => $s) {
            $result = preg_match($pattern, $s, $matches);
            if (!$result) {
                $lastKey = '';
                if ($s=='' || ctype_space($s)) {
                    if ($inHeader) {
                        $this->setHeaderEntry($headerEntry);
                        $entry = null;
                        $inHeader = false;
                    }
                    if (!$wsBreak) {
                        if (!($entry === null)) {
                            $this->addEntry($entry);
                        }
                        $entry = null;
                        $wsBreak=true;
                    }
                } else {
                    $wsBreak=false;
                    $unrecognized[$line+1] = $s;
                }
            } else {
                if ($entry === null) {
                    $entry = new PoEntry;
                }
                $wsBreak=false;
                $currentKey = $matches[2];  // will be used to set last key
                switch ($matches[2]) {
                    case PoTokens::TRANSLATOR_COMMENTS:
                    case PoTokens::EXTRACTED_COMMENTS:
                    case PoTokens::REFERENCE:
                    case PoTokens::FLAG:
                    case PoTokens::OBSOLETE:
                    case PoTokens::PREVIOUS:
                        $entry->add($matches[2], $matches[5]);
                        break;
                    case PoTokens::CONTEXT:
                    case PoTokens::MESSAGE:
                    case PoTokens::PLURAL:
                    case PoTokens::TRANSLATED:
                        $entry->addQuoted($matches[2], $matches[5]);
                        break;
                    default:
                        if ($matches[4]==PoTokens::CONTINUED_DATA) {
                            $currentKey = $lastKey; // keep the previous key
                            if ($currentKey==PoTokens::TRANSLATED_PLURAL) {
                                $entry->addQuotedAtPosition(
                                    PoTokens::TRANSLATED,
                                    $currentPlural,
                                    '"' . $matches[5]
                                );
                            } else {
                                $entry->addQuoted($currentKey, '"' . $matches[5]);
                            }
                        } elseif (substr($matches[2], 0, 7)==PoTokens::TRANSLATED_PLURAL) {
                            $currentKey = PoTokens::TRANSLATED_PLURAL;
                            $currentPlural = $matches[3];
                            $entry->addQuotedAtPosition(
                                PoTokens::TRANSLATED,
                                $currentPlural,
                                $matches[5]
                            );
                        } elseif (isset($matches[6][0])
                            && $matches[6][0]==PoTokens::TRANSLATOR_COMMENTS) {
                            $value = substr($matches[6], 1);
                            $value = empty($value) ? '' : $value;
                            $entry->add(PoTokens::TRANSLATOR_COMMENTS, $value);
                        } else {
                            $unrecognized[$line+1] = $s;
                        }
                        break;
                }
                $lastKey = $currentKey;
            }
        }
        if (!($entry === null)) {
            $this->addEntry($entry);
        }

        // throw at the very end, anything recognized has been processed
        $this->unrecognizedInput = $unrecognized;
        if (count($unrecognized)) {
            throw new UnrecognizedInputException();
        }
    }
1352631
public static function is($pattern, $value)
    {
        $patterns = Arr::wrap($pattern);

        if (empty($patterns)) {
            return false;
        }

        foreach ($patterns as $pattern) {
            // If the given value is an exact match we can of course return true right
            // from the beginning. Otherwise, we will translate asterisks and do an
            // actual pattern match against the two strings to see if they match.
            if ($pattern == $value) {
                return true;
            }

            $pattern = preg_quote($pattern, '#');

            // Asterisks are translated into zero-or-more regular expression wildcards
            // to make it convenient to check if the strings starts with the given
            // pattern such as "library/*", making any string check convenient.
            $pattern = str_replace('\*', '.*', $pattern);

            if (preg_match('#^'.$pattern.'\z#u', $value) === 1) {
                return true;
            }
        }

        return false;
    }
191399
function (source, pattern) {
    var results = [], match;
    while ((match = pattern.exec(source)) !== null)
      results.push(match[1]);
    return results;
  }
433624
private static function isValidRegex($pattern)
    {
        try {
            return preg_match(sprintf('~%s~', $pattern), null) !== false;
        } catch (\Exception $e) {
            return false;
        }
    }
1002468
public function matchQuery($pattern, &$matches = null, $flags = 0, $offset = 0)
	{
		return preg_match($pattern, $this->_query ?: '', $matches, $flags, $offset);
	}
545412
private function _regexMatch(string $pattern, int &$offset)
    {
        $idx = $offset;
        if (!preg_match($pattern, substr($this->_dn, $idx), $match)) {
            return null;
        }
        $idx += strlen($match[0]);
        $offset = $idx;
        return end($match);
    }
548674
private function matchByRegex(string $pattern, string $path): array
    {
        $isPatternMatched = (bool) \preg_match_all("~^$pattern$~", $path, $matches);

        if (!$isPatternMatched) {
            return [$isPatternMatched, []];
        }

        foreach ($matches as $k => $match) {
            $match = \array_shift($match);
            if (\is_int($k) || empty($match)) {
                unset($matches[$k]);
                continue;
            }
            $matches[$k] = $match;
        }

        return [$isPatternMatched, $matches];
    }
707702
public function match($source)
    {
        $this->factory->setType(Token::START);

        return parent::match($source);
    }
914980
public function matchPath($pattern, &$matches = null, $flags = 0, $offset = 0)
	{
		return preg_match($pattern, $this->_path ?: '', $matches, $flags, $offset);
	}
294599
public function match($URL, $method='get'){
      $method = strtolower($method);

      // * is an http method wildcard
      if (empty($this->methods[$method]) && empty($this->methods['*'])) return false;

      return (bool) (
        $this->dynamic
           ? preg_match($this->matcher_pattern, '/'.trim($URL,'/'))
           : rtrim($URL,'/') == rtrim($this->pattern,'/')
      );
    }
1055744
public function match($pattern) {
        if (!$this->_isValid) {
            return $this;
        }
        if (!preg_match($pattern, $this->_unsafeVar)) {
            $this->_isValid = false;
        }
        return $this;
    }
1174478
public function hasFilesWithName($pattern)
    {
        $result = $this->getFiles(Finder::create()->name($pattern));

        return count($result) !== 0;
    }
125357
public function contains($pattern, $regexp = FALSE)
  {
    if(empty($pattern))
    {
      return TRUE;
    }

    if($regexp)
    {
      return (preg_match("/" . $pattern . "/i", $this->string)) ? TRUE : FALSE;
    }
    else
    {
      return (stristr($this->string, $pattern) !== FALSE) ? TRUE : FALSE;
    }
  }