Validate an input string and perfOne a replace on all ocurrences
of $this->search with $this->replace
@return string
424758
protected function _str_replace_outside_quotes()
        {
            $re_valid = '/
                # Validate string having embedded quoted substrings.
                ^                           # Anchor to start of string.
                (?:                         # Zero or more string chunks.
                  "[^"\\\\]*(?:\\\\.[^"\\\\]*)*"  # Either a double quoted chunk,
                | \'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'  # or a single quoted chunk,
                | [^\'"\\\\]+               # or an unquoted chunk (no escapes).
                )*                          # Zero or more string chunks.
                \z                          # Anchor to end of string.
                /sx';

            if (!preg_match($re_valid, $this->subject)) {
                throw new OneStringException("Subject string is not valid in the replace_outside_quotes context.");
            }

            $re_parse = '/
                # Match one chunk of a valid string having embedded quoted substrings.
                  (                         # Either $1: Quoted chunk.
                    "[^"\\\\]*(?:\\\\.[^"\\\\]*)*"  # Either a double quoted chunk,
                  | \'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'  # or a single quoted chunk.
                  )                         # End $1: Quoted chunk.
                | ([^\'"\\\\]+)             # or $2: an unquoted chunk (no escapes).
                /sx';

            return preg_replace_callback($re_parse, array($this, '_strReplaceOutsideQuotesCb'), $this->subject);
        }
361230
public function refresh_search()
    {
        if (!empty($this->search_string)) {
            $this->search(
                is_object($this->search_set) ? $this->search_set->get_parameters('MAILBOX') : '',
                $this->search_string,
                $this->search_charset,
                $this->search_sort_field
            );
        }

        return $this->get_search_set();
    }
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;
	}
406075
public function createRegex()
    {
        $parts = explode('/', ltrim($this->path, '/'));
        $regex = '/^'; // Matches the start of the string
        foreach ($parts as $part) {
            $regex .= '\/'; // Matches starting slash
            // Handle non-variable parts
            if (stripos($part, '{') === false &&
                stripos($part, '}') === false) {
                $regex .= $part; // Exactly match this part
                continue;
            }
            // Handle variable parts
            $name = str_ireplace(['{', '}'], '', $part);
            $this->parameterNames[] = $name;
            $this->parameters[$name] = null;
            // Check if a rule exists for this part
            if (isset($this->rules[$name])) {
                $regex .= $this->rules[$name];
                continue;
            }
            // No rule exists, match all except slashes
            $regex .= '([^\/]+)';
        }
        $regex .= '$/'; // Matches end of string
        $this->regex = $regex;
    }
1035411
public function message()
	{
		$params = func_get_args();

		$message = array_shift( $params );
		$method = array_shift( $params );

		if ( !$result = $this->validate( $method, $params ) )
		{
			$key = array_shift( $params );

			$params = $this->get_error_message_params( $key, $params );

			// replace the params inside the line
			foreach ( $params as $param => $value ) 
			{
				$message = str_replace( ':'.$param, $value, $message );
			}

			$this->errors[$key][] = $message;
		}

		return $result;
	}
225956
public function getAsString(): string
    {
        $text = $this->source->getAsString();

        $stripAll = new StripAllFilter();
        $htmlFilter = new HtmlFilter();

        /* Removing CDATA tags */
        $text = preg_replace_callback(
            '#<!\[CDATA\[(.*?)\]\]>#ums',
            function ($match) use ($htmlFilter) {
                $string = $htmlFilter->filter($match[1]);

                //      <![CDATA[               ]]
                return '         ' . $string . '  ';
            },
            $text
        );

        /* Processing bottom level tags */
        $text = preg_replace_callback(
            '#(<(\w+)(\s[^>]*?)?>)([^<>]*)(</\w+\s*>)#um',
            function ($match) use ($stripAll) {
                if (strtolower($match[2]) === 'target') {
                    $replace = $stripAll->filter($match[1]) . $match[4]
                        . $stripAll->filter($match[5]);
                } else {
                    $replace = $stripAll->filter($match[0]);
                }

                return $replace;
            },
            $text
        );

        /* Other replacements */
        foreach ($this->filters as $pattern => $filter) {
            if (null === $filter) {
                $filter = $stripAll;
            }
            $text = preg_replace_callback(
                $pattern,
                function ($match) use ($filter) {
                    return $filter->filter($match[0]);
                },
                $text
            );
        }

        return $text;
    }
801974
public function validate()
    {
        $matchers = [];

        // #1: find matchers.
        foreach ($this->getFluent()->getCalls() as $key) {
            // Keyword "not" inverses the end result.
            // Using it twice in the same assertion will have no effect (see the code).
            if ("not" == $key) {
                $this->inverse = true;

                continue;
            }

            if (is_array($key)) {
                // Handle "matcher+link+arguments" (instead of "matcher+arguments") cases.
                if (in_array($key[0], $this->links) and count($matchers) > 0) {
                    $lastIndex = count($matchers) - 1;
                    $matchers[$lastIndex] = [$matchers[$lastIndex], $key[1]];
                } else {
                    $matchers[] = $key;
                }

                continue;
            }

            // If the given keyword is NEITHER a link NOR "should", it must be a matcher name.
            if ( ! in_array($key, $this->links) && "should" != $key) {
                $matchers[] = $key;
            }
        }

        // If no matchers were found, just return "true" (there is no way it can be "false").
        if (count($matchers) == 0) {
            return true;
        }

        // Think of "{{link}}(smth)" as "equal(smth)".
        if (is_array($matchers[0]) and in_array($matchers[0][0], $this->links)) {
            $matchers[0][0] = "equal";
        }

        // #2: initialize the matchers.
        foreach ($matchers as $key => $matcher) {
            $class = $this->aliasToMatcher(is_array($matcher) ? $matcher[0] : $matcher);

            if ( ! class_exists($class)) {
                throw new Exceptions\NoMatcherFoundException($class);
            }

            $matchers[$key] = new $class(
                // @codeCoverageIgnoreStart
                $this->value, // The value we're working with.
                (is_array($matcher) ? $matcher[1] : []), // The matcher arguments.
                // Whether it should be in "configuration" or "normal" mode.
                (count($matchers) - 1 != $key) && count($matchers) != 1
            );
            // @codeCoverageIgnoreEnd
        }

        $result = true;

        // #3: run the matchers!
        foreach ($matchers as $matcher) {
            $this->lastMatcher = $matcher;

            if ( ! $matcher->run()) {
                $this->message = $matcher->getMessage();
                $result = false;

                break;
            }

            // We want to grab the message anyway.
            $this->message = $matcher->getMessage();
        }

        // #4: if the result should be inversed, do it.
        if ($this->inverse) {
            $this->inverse = false;
            $result = ! $result;

            $this->message = "NOT keyword (failed): ".$this->message;
        }

        return $result;
    }
33120
public function validate( $input )
    {
        // Check if regular expression matches the input string.
        if ( !preg_match( $this->regexp, $input ) )
        {
            throw new phpillowValidationException(
                'Input %input did not match regular expression %expression.', 
                array(
                    'input' => $input,
                    'expression' => $this->regexp,
                )
            );
        }

        return (string) $input;
    }
1171202
private function validate($scheme): ?string
    {
        $scheme = $this->filterComponent($scheme);
        if (null === $scheme) {
            return $scheme;
        }

        if (1 === preg_match(self::REGEXP_SCHEME, $scheme)) {
            return strtolower($scheme);
        }

        throw new SyntaxError(sprintf("The scheme '%s' is invalid", $scheme));
    }
195276
public function getRegex()
    {
        switch ($this->decimalPoint) {
            case self::DECIMAL_COMMA:
                $regex = '/^-?\d+(,\d+)?$/';
                break;

            case self::DECIMAL_POINT_OR_COMMA:
                $regex = '/^-?\d+((\.|,)\d+)?$/';
                break;

            case self::DECIMAL_POINT:
            default:
                $regex = '/^-?\d+(\.\d+)?$/';
                break;
        }

        return $regex;
    }
1044520
public function strip()
    {
        if (empty($this->_message))
            throw new RuntimeException("A message has not been set");

        $messageBody = $this->_message;
        if (preg_match_all($this->_regex, $messageBody, $matches)) {
            foreach ($matches[0] as $k => $header) {
                $startPos = strpos($messageBody, $header);
                $lookAhead = $k+1;
                $afterPos = array_key_exists($lookAhead, $matches[0]) ?
                    strpos($messageBody, $matches[0][$lookAhead]) : strlen($messageBody);

                $messageBody = substr($messageBody, 0, $startPos) . " " . substr($messageBody, $afterPos);
            }
        }

        return trim($messageBody);
    }
944921
public function accept()
    {
        $candidate = $this->getInnerIterator()->current();

        // Check that the candidate file (a full file path) ends in the pattern we are searching for.
        return strrpos($candidate, $this->file) === strlen($candidate) - strlen($this->file);
    }
823145
public function validateString()
    {
        $len = function_exists('mb_strlen') ? mb_strlen($this->getValue()) : strlen($this->getValue());

        return $len >= $this->getArg(0) && $len <= $this->getArg(1);
    }
75892
protected function replaceKeyPlaceholders()
    {
        if ( ! $this->model) {
            return $this;
        }

        $placeholder = static::MODEL_KEY_PLACEHOLDER;

        foreach ($this->rules as $key => &$ruleSet) {

            if (is_string($ruleSet)) {

                $ruleSet = str_replace($placeholder, $this->model->getKey(), $ruleSet);
                continue;
            }

            if (is_array($ruleSet)) {

                foreach ($ruleSet as &$rule) {
                    $rule = str_replace($placeholder, $this->model->getKey(), $rule);
                }

                unset($rule);
            }
        }

        unset($ruleSet);

        return $this;
    }
1080696
public function getErrorsAsString()
    {
        $string = '';
        foreach ($this->getErrors() as $error) {
            $string .= sprintf(
                "%s: %s",
                $error['field'],
                $error['message']
            );
            if (isset($error['rejected'])) {
                $string .= sprintf(" ('%s' given)", $error['rejected']);
            }
            $string .= ";\n";
        }

        return trim($string);
    }
855141
private function validate() {
        $filterer = new Filterer();
        $valid = true;
        foreach ($this->elements as $element) {
            if (!$element->validate($filterer, $this->data))
                $valid = false;
            $this->data[$element->name] = ($element->type === 'fieldset') ?
                    $element->options->value->getData(true) : $element->data;
        }
        $this->valid = $valid;
        return $valid;
    }
1269571
private function input() {
		if ($this->input===null) {
			$this->input=new ValidationInputOne($this->prefix,$this->messageList); // we used the same message list
		}
		return $this->input;
	}