Preg Replace Callback
Uses matches made earlier runs geshi returns processed code blocks.

@return string Completed replacement string
428611
protected function _processCodeBlock($matches)
    {
        list($block, $openTag, $tagName, $lang, $code, $closeTag) = $matches;
        unset($matches);

        // check language
        $lang = $this->validLang($lang);
        $code = html_entity_decode($code, ENT_QUOTES); // decode text in code block as GeSHi will re-encode it.

        if (isset($this->containerMap[$tagName])) {
            $patt = '/' . preg_quote($tagName) . '/';
            $openTag = preg_replace($patt, $this->containerMap[$tagName][0], $openTag);
            $closeTag = preg_replace($patt, $this->containerMap[$tagName][1], $closeTag);
        }

        if ($this->showPlainTextButton) {
            $button = '<a href="#null" class="geshi-plain-text">Show Plain Text</a>';
            $openTag = $button . $openTag;
        }

        if ($lang) {
            $highlighted = $this->highlightText(trim($code), $lang);
            return $openTag . $highlighted . $closeTag;
        }
        return $openTag . $code . $closeTag;
    }
1136988
protected function getTokenReplaces()
    {
        $replaces = array();

        foreach ($this->tokens as $token => $value) {
            $key              = $this->getFormatter()->untokenize($token);
            $formatter        = $this->getTokenFormatter($key);
            $replaces[$token] = $formatter::format($value);
        }

        return $replaces;
    }
686344
public function doRegexpReplace($searchPattern, $replaceWith)
    {
        $this->content = preg_replace_callback(
            $searchPattern,
            function($matches) use ($replaceWith) {
                $indent = isset($matches['indent']) ? $matches['indent'] : '';
                $output = $indent;
                $output .= isset($matches['start']) ? $matches['start'] : '';
                $output .= isset($matches['target']) ? Formatter::indentLines($replaceWith, mb_strlen($indent), true) : '';
                $output .= isset($matches['end']) ? $matches['end'] : '';

                return $output;
            },
            $this->content
        );

        return $this;
    }
584138
public function getCharset() {
		if (!isset($this->charset)) {
			$numOfMatches = preg_match('/charset\s*=([^;]*)/', $this->getHeader('Content-Type'), $matches);
			if ($numOfMatches) {
				$this->charset = trim($matches[1]);
			} else {
				$this->charset = '';
			}
		}
		return $this->charset;
	}
1162154
public function regex()
    {
        // Turn "(/)" into "/?"
        $uri = preg_replace('#\(/\)#', '/?', $this->uri);

        // Create capture group for ":parameter", replaces ":parameter"
        $uri = $this->capture($uri, '/:(' . self::ALLOWED_REGEX . ')/');

        // Create capture group for '{parameter}', replaces "{parameter}"
        $uri = $this->capture($uri, '/{(' . self::ALLOWED_REGEX . ')}/');

        // Add start and end matching
        return (string) '@^' . $uri . '$@D';
    }
1084946
function strReplace()
    {
        if (($this->getParameter('needle') == null) || ($this->getParameter('haystack') == null))
            return $this->getParameter('haystack');

        $needle = $this->getParameter('needle');
        if($needle == '\n')
            $needle = "\n";

        return str_replace($needle, $this->getParameter('replace'), $this->getParameter('haystack'));
    }
71343
public function cleanString()
		{
			//get rid of newline holders in values
			$this->processString = str_replace('\\\\\\\\n', ' ', $this->processString);

			//replace newline holders with newline
			$this->processString = str_replace('\n', "\n", $this->processString);

			//match returns extra curly bracket at EOL, get rid of it
			$this->processString = substr($this->processString, 0, -1);

			//convert unicode encoded characters to html entities hex
			$this->processString = preg_replace('/\\\\u([0-9a-fA-F]{4})/', '&#x$1;', $this->processString);

			//get rid of escapes added for javascript
			$this->processString = stripslashes($this->processString);
		}
656634
public function replace() {

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

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

				$match 		= new MatchVariable($this -> match[1][$index]);
				$variables  = $match -> replace() -> getLine();

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

		return $this;
	}
334087
protected function regexEncoding()
	{
		trigger_error('Function ' . __METHOD__ . ' not implemented yet');

		static $functionExists;

		if ($functionExists === null) {
			$functionExists = function_exists('\mb_regex_encoding');
		}

		if ($functionExists) {
			$args = func_get_args();
			return call_user_func_array('\mb_regex_encoding', $args);
		}
	}
781875
private function findPattern($matches) {
        switch ($matches[1]) {
            case ':num':
                $replacement = '([0-9]';
                break;
            case ':alpha':
                $replacement = '([a-zA-Z]';
                break;
            case ':any':
                $replacement = '([^\/]';
                break;
        }


        if (isset($matches[3]) && is_numeric($matches[3])) {
            if (isset($matches[4]) && $matches[4] == '?') {
                $replacement .= '{0,' . $matches[3] . '})';
            } else {
                $replacement .= '{' . $matches[3] . '})';
            }
        } else {
            if (isset($matches[4]) && $matches[4] == '?') {
                $replacement .= '*)';
            } else {
                $replacement .= '+)';
            }
        }

        return $replacement;
    }
793623
public function replaceUnicodeWithNamed($string)
    {
        $index = $this->getIndex();

        return preg_replace_callback($index->getEmojiUnicodeRegex(), function ($matches) use ($index) {
            $emoji = $index->findByUnicode($matches[0]);

            return ':'.$emoji['name'].':';
        }, $string);
    }
1315407
public function searchAndReplace()
	{
		$this->search();

		$this->replacement = new Replacement($this->formatted, $this->str);

		$this->replacement->replace();
		
		return $this->replacement->getStr();
	}
1068647
protected function build_regex() {
        if (!is_null($this->regex)) {
            return $this->regex;
        }

        $decsep = preg_quote($this->decsep, '/');
        $thousandssep = preg_quote($this->thousandssep, '/');
        $beforepointre = '([+-]?[' . $thousandssep . '\d]*)';
        $decimalsre = $decsep . '(\d*)';
        $exponentre = '(?:e|E|(?:x|\*|×)10(?:\^|\*\*))([+-]?\d+)';

        $numberbit = "{$beforepointre}(?:{$decimalsre})?(?:{$exponentre})?";

        if ($this->unitsbefore) {
            $this->regex = "/{$numberbit}$/";
        } else {
            $this->regex = "/^{$numberbit}/";
        }
        return $this->regex;
    }
904366
public function tags_preg_callback($matches)
    {
        switch (strtolower($matches[1])) {
        case 'b':
        case 'strong':
            return $this->_toupper($matches[3]);
        case 'th':
            return $this->_toupper("\t\t". $matches[3] ."\n");
        case 'h':
            return $this->_toupper("\n\n". $matches[3] ."\n\n");
        case 'a':
            // Remove spaces in URL (#1487805)
            $url = str_replace(' ', '', $matches[3]);
            return $this->_build_link_list($url, $matches[4]);
        }
    }
1156776
public function regexReplace($pattern, $replacement, $limit = -1)
    {
        if (\is_callable($replacement)) {
            $rxp_function = '\preg_replace_callback';
        } else {
            $rxp_function = '\preg_replace';
        }

        $this->string = $rxp_function($pattern, $replacement, $this->string, $limit);

        return $this;
    }
907554
public function pregReplace()
    {
        if ($this->getParameter('pattern') == null)
            return $this->getParameter('subject');
        return preg_replace($this->getParameter('pattern'), $this->getParameter('replace'), $this->getParameter('subject'));
    }
785366
protected static function replaceBlock(array $matches)
    {
        $matches[3] = self::removeTrailingNewline($matches[3]);

        if (preg_match_all(self::$regex, self::$childSource, $override) && in_array($matches[2], $override[2])) {
            $key      = array_search($matches[2], $override[2]);
            $override = self::removeTrailingNewline($override[3][$key]);

            $l = stripslashes(self::$l);
            $r = stripslashes(self::$r);

            if (self::$lastReplacement) {
                return preg_replace('/' . self::$l . '\$dwoo\.parent' . self::$r . '/is', $matches[3], $override);
            }

            return $l . 'block ' . $matches[1] . $matches[2] . $matches[1] . $r . preg_replace('/' . self::$l . '\$dwoo\.parent' . self::$r . '/is', $matches[3], $override) . $l . '/block' . $r;
        }

        if (preg_match(self::$regex, $matches[3])) {
            return preg_replace_callback(self::$regex, array(
                'Dwoo\Plugins\Functions\PluginExtends',
                'replaceBlock'
            ), $matches[3]);
        }

        if (self::$lastReplacement) {
            return $matches[3];
        }

        return $matches[0];
    }