@param string $pattern

@return string

@throws UnknownPatternException
438135
private function transformPatternToRegexWithSupportedPolicy($pattern)
    {
        foreach ($this->policies as $policy) {
            if ($policy->supportsPattern($pattern)) {
                return $policy->transformPatternToRegex($pattern);
            }
        }

        throw new UnknownPatternException(sprintf('Can not find policy for a pattern `%s`.', $pattern), $pattern);
    }
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;
    }
1088835
public function notMatch($pattern) {
        if (!$this->_isValid) {
            return $this;
        }
        if (preg_match($pattern, $this->_unsafeVar)) {
            $this->_isValid = false;
        }
        return $this;
    }
1110236
static public function prepareXsdPatternForPcre($pattern)
    {
        // XML schema always implicitly anchors the entire regular expression
        // because there is no carret (^) nor dollar ($) signs.
        // see http://www.regular-expressions.info/xml.html
        $pattern = self::escapeSymbols($pattern, array('$', '^'));
        $pattern = self::pregAddDelimiter('^' . $pattern . '$');

        // XSD regexp always case-sensitive (nothing to do), dot matches white-spaces (use PCRE_DOTALL).
        $pattern .= 's';
        
        return $pattern;
    }
1058530
public function escapeLikePattern(string $pattern): string {
		$esc = $this->getLikeEscapeCharacter();
		return str_replace(array($esc, QueryComparator::LIKE_WILDCARD_MANY_CHARS,
				QueryComparator::LIKE_WILDCARD_ONE_CHAR),
				array($esc . $esc,  $esc . QueryComparator::LIKE_WILDCARD_MANY_CHARS, $esc .
						QueryComparator::LIKE_WILDCARD_ONE_CHAR), $pattern);
	}
371390
public function matchesPattern($event, $pattern)
    {
        if ($pattern === '*') {
            return true;
        }

        if ($event == $pattern) {
            return true;
        }

        return fnmatch($pattern, $event);
    }
975012
static protected function analysisPattern($pattern)
    {
        if (!($n = self::$_mbstringAvailable ? mb_strlen($pattern, APP_CHARSET) : strlen($pattern))) {
            return [];
        }
        $ps = [];
        $c0 = self::$_mbstringAvailable ? mb_substr($pattern, 0, 1, APP_CHARSET) : substr($pattern, 0, 1);

        for ($start = 0, $i = 1; $i < $n; ++$i) {
            $c = self::$_mbstringAvailable ? mb_substr($pattern, $i, 1, APP_CHARSET) : substr($pattern, $i, 1);
            if ($c !== $c0) {
                $ps[] = self::$_mbstringAvailable ? mb_substr($pattern, $start, $i - $start, APP_CHARSET) : substr($pattern, $start, $i - $start);
                $c0 = $c;
                $start = $i;
            }
        }
        $ps[] = self::$_mbstringAvailable ? mb_substr($pattern, $start, $n - $start, APP_CHARSET) : substr($pattern, $start, $n - $start);
        return $ps;
    }
35075
function indexOfPattern ($pattern)
  {
    self::toUnicodeRegex ($pattern);
    if (!preg_match ($pattern, $this->S, $m, PREG_OFFSET_CAPTURE)) return false;
    return $m[0][1];
  }
988360
protected function buildRegExp($pattern)
    {
        $pattern = '/' . trim($pattern, '/');
        $pattern = str_replace('/', '\/', $pattern);
        preg_match_all('#((\\\/)?[^\\\/]+)#im', $pattern, $patternMatches);

        foreach ($patternMatches[1] as &$match) {
            if (strpos($match, '*') !== false) {
                $match = str_replace('*', self::ANY, $match);
            }

            if (preg_match('#\(![^\)]+\)#i', $match)) {
                $match = preg_replace_callback(
                    '/^(.*)\(!([^\)]+)\)$/i',
                    array($this, 'buildRegExpCallback'),
                    $match,
                    \PREG_SET_ORDER
                );
            }

            unset($match);
        }

        $pattern = str_replace($patternMatches[0], $patternMatches[1], $pattern);
        $pattern = '/^' . $pattern . '\/?.*$/i';

        return $pattern;
    }
1277652
public function setPattern($pattern)
    {
        if (gettype($pattern) === 'string') {
            $this->pattern = $pattern;
        } else {
            $msg = "The pattern argument must be a string or a variable reference, '" . $pattern . "' given.";
            throw new InvalidArgumentException($msg);
        }
    }
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;
    }
1086363
public function setPath($pattern)
    {
        if (false !== strpbrk($pattern, '?<')) {
            $pattern = preg_replace_callback('#\{(\w++)(<.*?>)?(\?[^\}]*+)?\}#', function ($m) {
                if (isset($m[3][0])) {
                    $this->setDefault($m[1], '?' !== $m[3] ? substr($m[3], 1) : null);
                }
                if (isset($m[2][0])) {
                    $this->setRequirement($m[1], substr($m[2], 1, -1));
                }

                return '{'.$m[1].'}';
            }, $pattern);
        }

        // A pattern must start with a slash and must not have multiple slashes at the beginning because the
        // generated path for this route would be confused with a network path, e.g. '//domain.com/path'.
        $this->path = '/'.ltrim(trim($pattern), '/');
        $this->compiled = null;

        return $this;
    }
1230281
public function getPattern() : ?string 
    {
        if ( ! $this->hasPattern()) {
            $this->setPattern($this->getDefaultPattern());
        }
        return $this->pattern;
    }
1048954
protected function compile($pattern)
    {
        if (isset($this->compileCache[$pattern])) {
            return $this->compileCache[$pattern];
        }

        $pcre = '(^';

        do {
            switch (true) {
                case preg_match('(^[^{]+)', $pattern, $match):
                    $pattern = substr($pattern, strlen($match[0]));
                    $pcre .= preg_quote($match[0]);
                    break;

                case preg_match('(^' . self::STANDARD_VARIABLE_REGEX . ')', $pattern, $match):
                    $pattern = substr($pattern, strlen($match[0]));
                    $pcre .= '(?P<' . $match[1] . '>[^/]+)';
                    break;

                case preg_match('(^' . self::SLASHES_VARIABLE_REGEX . ')', $pattern, $match):
                    $pattern = substr($pattern, strlen($match[0]));
                    $pcre .= '(?P<' . $match[1] . '>.+)';
                    break;

                default:
                    throw new Exceptions\InvalidArgumentException("Invalid pattern part: '$pattern'.");
            }
        } while ($pattern);

        $pcre .= '$)S';

        $this->compileCache[$pattern] = $pcre;

        return $pcre;
    }
1208799
public function path($pattern = null)
    {
        if (isset($pattern)) {
            return preg_match("~$pattern~i", $this->path) === 1;
        }

        return $this->path;
    }
351163
private function getRegexPatternFromHtmlErrorPattern($pattern)
    {
        $regexPattern = '';

        foreach ($pattern as $part) {
            if ($this->isTokenPatternPart($part)) {
                $regexPattern .= '.*';
            } else {
                $regexPattern .= PregQuoter::quote($part);
            }
        }

        return '/' . $regexPattern . '/is';
    }
375024
protected function assertPattern($pattern)
    {
        if (strlen($pattern) == 0) return null;

        $pattern = '/^'. str_replace('/', '\\/', $pattern). '$/';
        if (@preg_match($pattern, null) === false) {
            throw new DefinitionException("invalid regular expression pattern");
        }

        return $pattern;
    }