Computes and returns regular expression pattern for matching and replacement.

@return string
517307
private function getExpression()
    {
        if ($this->expression === null) {
            $this->expression =
                '/(<\?xml.*\?>)?([ \t\n\r]*)(<' .
                preg_quote($this->documentElement, '/') .
                '.*xmlns="' .
                preg_quote($this->namespace, '/') .
                '".*>)/is';
        }

        return $this->expression;
    }
1171559
protected function getExtensionsRegex()
    {
        $regex = '';
        $last = count($this->extensions) - 1;
        foreach ($this->extensions as $index => $ext) {
            $regex .= '\.'.$ext.'$';
            $regex .= $index !== $last ? '|' : '';
        }

        return '('.$regex.')';
    }
376637
protected function getRegex()
    {

        if( !self::$regexDefault ) {
            self::$regexDefault = implode(
                '|',
                array_map(
                    function($value){
                        return "(?<=[a-z0-9]){$value}(?=[A-Z])";
                    },
                    array_flip( self::$operations )
                )
            );
            self::$regexDefault = "/".self::$regexDefault."/";
        }

        return self::$regexDefault;

    }
362121
public function getRegexp()
	{
		$hosts = [];
		foreach ($this->items as $host)
		{
			$hosts[] = $this->normalizeHostmask($host);
		}

		$regexp = RegexpBuilder::fromList(
			$hosts,
			[
				// Asterisks * are turned into a catch-all expression, while ^ and $ are preserved
				'specialChars' => [
					'*' => '.*',
					'^' => '^',
					'$' => '$'
				]
			]
		);

		return '/' . $regexp . '/DSis';
	}
513553
private function getUrlTemplate()
    {
        $filter = $this->getFilter();
        $item   = current($this->getFilter()->getItems());

        $regexp      = "/({$filter->getRequestVar()})=(-?[0-9]+)/";
        $replacement = '${1}=<%- from %>-<%- to %>';

        return preg_replace($regexp, $replacement, $item->getUrl());
    }
564847
protected function getScanExcludePattern()
    {
        $pattern = implode('|', array_keys(array_filter((array)$this->settings['scan']['excludePatterns'])));
        if ($pattern !== '') {
            $pattern = '#' . str_replace('#', '\#', $pattern) . '#';
        }
        return $pattern;
    }
1138986
public function replace() {

		if(null !== $this -> match) {

			foreach($this -> match[0] as $index => $match) {

				$code = '<?php endforeach; ?>';
				$this -> line = preg_replace('/' . preg_quote($this -> match[0][$index], '/') . '/', $code, $this -> line , 1);
			}
		}

		return $this;
	}
99823
protected function findReplacements($pattern)
    {
        if (0 !== strpos($pattern, '@')) {
            return $pattern;
        }

        $replace = [
            '@yearly'   => '0 0 1 1 * *',
            '@annually' => '0 0 1 1 * *',
            '@monthly'  => '0 0 1 * *',
            '@weekly'   => '0 0 * * 0',
            '@daily'    => '0 0 * * *',
            '@hourly'   => '0 * * * *',
        ];
        if (isset($replace[$pattern])) {
            $pattern = $replace[$pattern];
        }

        return $pattern;
    }
528600
protected function getDefaultPattern()
    {
        $patternParts = [];
        if (self::NONE !== $this->datetype) {
            $patternParts[] = $this->defaultDateFormats[$this->datetype];
        }
        if (self::NONE !== $this->timetype) {
            $patternParts[] = $this->defaultTimeFormats[$this->timetype];
        }

        return implode(', ', $patternParts);
    }
653920
private static function getReplacements()
    {
        if (null !== self::$replacements) {
            return self::$replacements;
        }

        self::$replacements = array(
            // Trailing single-wildcard with separator prefix
            '/\\\\\.\\\\\*$/'     => '(?:\.\w+)?',
            // Single-wildcard with separator prefix
            '/\\\\\.\\\\\*/'      => '(?:\.\w+)',
            // Single-wildcard without separator prefix
            '/(?<!\\\\\.)\\\\\*/' => '(?:\w+)',
        );

        // preg_quote() escapes `#` in PHP 7.3+
        if (PHP_VERSION_ID >= 70300) {
            self::$replacements += array(
                // Multi-wildcard with separator prefix
                '/\\\\\.\\\\\#/'      => '(?:\.\w+)*',
                // Multi-wildcard without separator prefix
                '/(?<!\\\\\.)\\\\\#/' => '(?:|\w+(?:\.\w+)*)',
            );
        } else {
            self::$replacements += array(
                // Multi-wildcard with separator prefix
                '/\\\\\.#/'      => '(?:\.\w+)*',
                // Multi-wildcard without separator prefix
                '/(?<!\\\\\.)#/' => '(?:|\w+(?:\.\w+)*)',
            );
        }

        return self::$replacements;
    }
1063741
protected function getEmbeddedRegexp()
    {
        // we need to alter the regexp we usr for std ref resolving, as it will be used to match parts of text, not the whole string
        $regexp = substr($this->getRegexp(), 1, -1);
        return '/' . preg_quote($this->beginToken). preg_replace(array('/^\^/'), array(''), $regexp) . '[^' . $this->endToken . ']+' . preg_quote($this->endToken) . '/';
    }
850865
protected function getTemplateRegexPattern()
    {
        $parts = explode('@', $this->template);
        if (count($parts) === 2) {
            $parts[0]    = str_replace('*', self::$nameRegex, $parts[0]);
            $topTLDIndex = strrpos($parts[1], '.');


            if ($topTLDIndex !== FALSE) {
                $secondTLD = substr($parts[1], 0, $topTLDIndex);
                $secondTLD = str_replace('*', self::$domainSecondTLDRegex, $secondTLD);

                $topTLD   = substr($parts[1], $topTLDIndex);
                $topTLD   = str_replace('*', self::$domainTLDRegex, $topTLD);
                $template = $parts[0] . '@' . $secondTLD . $topTLD;
            } else {
                $template = $parts[0] . '@' . $parts[1];
            }
        } else {
            $template = '';
        }

        //$template = str_replace(['.', '+', '-'], ['\.', '\+', '\-'], $template);

        return sprintf('/^%s$/', $template);
    }
843706
protected function getRegex()
    {
        if ($this->regex === null) {
            $this->regex = $this->buildRegex($this->getTokens(), $this->constraints);
        }

        return $this->regex;
    }
1046082
public function parse(){
    preg_match_all($this->pattern['start'], $this->source, $matches, PREG_OFFSET_CAPTURE);
    if ( isset($matches[0]) ){
      foreach ( $matches[0] as $match ){
        preg_match($this->pattern['end'], $this->source, $mat, PREG_OFFSET_CAPTURE, $match[1]);
        $start = $match[1];
        $length = isset($mat[0]) ? ($mat[0][1] - $start) + 3 : 0;
        $this->parsed[] = $this->parse_docblock(substr($this->source, $start, $length));
      }
    }
    return $this->parsed;
  }
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));
        });
    }
854347
public static String preg_replace(Pattern pattern, String replacement, String subject) {
        Matcher m = pattern.matcher(subject);
        StringBuffer sb = new StringBuffer(subject.length());
        while(m.find()){ 
            m.appendReplacement(sb, replacement);
        }
        m.appendTail(sb);
        return sb.toString();
    }
970268
protected function compile()
	{
		if ($this->compiled !== false)
		{
			return $this->compiled;
		}

		if ($this->isStatic())
		{
			$this->compiled = '~^'.$this->pattern.'$~';
			return $this->compiled;
		}

		$compiled = $this->pattern;
		foreach ($this->getSegments($compiled) as $segment)
		{
			$compiled = \str_replace($segment['token'], $segment['regex'], $compiled);
		}

		$this->compiled = "~^{$compiled}$~";
		return $this->compiled;
	}