@param $pattern

@return string
513848
protected function removeQuantifier($pattern)
	{
		if (strripos($pattern, '+') !== false && strripos($pattern, '\+') === false)
		{
			return rtrim($pattern, '+');
		}
		if (strripos($pattern, '*') !== false && strripos($pattern, '\*') === false)
		{
			return rtrim($pattern, '*');
		}
		if (strripos($pattern, '?') !== false && strripos($pattern, '\?') === false)
		{
			return rtrim($pattern, '?');
		}

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

        return false;
    }
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;
    }
35075
function indexOfPattern ($pattern)
  {
    self::toUnicodeRegex ($pattern);
    if (!preg_match ($pattern, $this->S, $m, PREG_OFFSET_CAPTURE)) return false;
    return $m[0][1];
  }
351163
private function getRegexPatternFromHtmlErrorPattern($pattern)
    {
        $regexPattern = '';

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

        return '/' . $regexPattern . '/is';
    }
32731
private function getMethods($pattern = "/^action_/") {
		$methos = get_class_methods($this->class);
		$actions = array();

		foreach ($methos as $methodName) {
			if (preg_match($pattern, $methodName)) {
				array_push($actions, $methodName);
			}
		}
		return $actions;
	}
640145
private function _getRandAddressCode($pattern)
    {
        $keys = array_keys($this->_addressCodeList);
        $result = preg_grep($pattern, $keys);

        return $result[array_rand($result)];
    }
349365
public static function createPattern($pattern)
    {
        $numVer = '([0-9]+|x|\*)';
        $numVer2 = '('.$numVer.'\.'.$numVer.')';
        $numVer3 = '('.$numVer.'\.'.$numVer.'\.'.$numVer.')';

        return '/^'.'('.$numVer.'|'.$numVer2.'|'.$numVer3.')'.$pattern.'/';
    }
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;
    }
943207
public function transformPatternToRegex($pattern)
    {
        if (!isset($this->patternToRegexpCache[$pattern])) {
            $this->patternToRegexpCache[$pattern] = $this->transformPatternToRegexWithSupportedPolicy($pattern);
        }

        return $this->patternToRegexpCache[$pattern];
    }
155840
public static function checkRegexPattern($pattern)
  {
    $check = @preg_match($pattern, "anything"); // thats the easy way to check a pattern ;)
    if (is_integer($check) == false) return false;
    else return true;
  }
276083
public function keys($pattern)
    {
        $keys = $this->getDriver()->keys($pattern);

        if ($this->hasMaxSize()) {
            foreach ($keys as $index => $key) {
                if ($this->isMappedKey($key)) {
                    unset($keys[$index]);
                }
            }
        }
        return $keys;
    }
149565
public function whatIs($pattern)
    {
        if (! $this->adapter->isAbsolute($pattern)) {
            $pattern = $this->rootPath . $pattern;
        }

        $paths = $this->adapter->glob($pattern);

        if (count($paths) == 0)
            return 'nothing';
        if (count($paths) == 1)
            return ($this->adapter->isFile($paths[0])) ? 'file' : 'dir';
        return 'collection';
    }
75020
public static function convertToJsFormat($pattern)
    {
        if (false === strpos($pattern, 'yyyy')) {
            if (false !== strpos($pattern, 'yy')) {
                $pattern = str_replace('yy', 'yyyy', $pattern);
            } elseif (false !== strpos($pattern, 'y')) {
                $pattern = str_replace('y', 'yyyy', $pattern);
            }
        }

        $pattern = str_replace('d', 'D', $pattern);
        $pattern = str_replace('y', 'Y', $pattern);
        $pattern = str_replace('a', 'A', $pattern);

        return $pattern;
    }
1255882
protected function parsePattern($pattern)
    {
        $currentPos      = 0;
        $length          = strlen($pattern);
        $tokens          = [];
        $level           = 0;
        $quotedDelimiter = preg_quote($this->delimiter);

        while ($currentPos < $length) {
            preg_match('(\G(?P<literal>[^:{\[\]]*)(?P<token>[:\[\]]|$))', $pattern, $matches, 0, $currentPos);

            $currentPos += strlen($matches[0]);

            if (!empty($matches['literal'])) {
                $tokens[] = ['literal', $matches['literal']];
            }

            if ($matches['token'] === ':') {
                if (!preg_match(
                    '(\G(?P<name>[^:' . $quotedDelimiter . '{\[\]]+)(?:{(?P<delimiters>[^}]+)})?:?)',
                    $pattern,
                    $matches,
                    0,
                    $currentPos
                )) {
                    throw new Exception\RuntimeException('Found empty parameter name');
                }

                $tokens[] = [
                    'parameter',
                    $matches['name'],
                    isset($matches['delimiters']) ? $matches['delimiters'] : null
                ];

                $currentPos += strlen($matches[0]);
            } elseif ($matches['token'] === '[') {
                $tokens[] = ['optional-start'];
                $level++;
            } elseif ($matches['token'] === ']') {
                $tokens[] = ['optional-end'];
                $level--;

                if ($level < 0) {
                    throw new Exception\RuntimeException('Found closing bracket without matching opening bracket');
                }
            } else {
                break;
            }
        }

        if ($level > 0) {
            throw new Exception\RuntimeException('Found unbalanced brackets');
        }

        return $tokens;
    }
975847
protected function matchesPattern($pattern)
	{
		trigger_error('Function ' . __METHOD__ . ' not implemented yet');

		$regexEncoding = $this->regexEncoding();
		$this->regexEncoding($this->encoding);

		$match = \mb_ereg_match($pattern, $this->str);
		$this->regexEncoding($regexEncoding);

		return $match;
	}
469671
public function parse($pattern)
    {
        //reset must be extracted
        $this->mustBeExtracted = array();
        //filter to lower and remove accentued
        $filteredPattern = mb_strtolower($this->remove_accents($pattern));

        $terms = $this->extractTerms($filteredPattern);
        $terms['_domain'] = $this->extractDomain($filteredPattern);
        $terms['_default'] = $this->extractDefault($filteredPattern);

        return $terms;
    }