Function that replace patterns with theirs values.

@param $patternString
@param Model $model

@return mixed|string
327099
public static function replace($patternString, $model) {
		//$patternString = '%%model_title%% %%sep%% %%appParam_contactEmail%% %%viewParam_titleSeparator%% %%appConfig_name%%';
		$replacedString = '';
		$patterns = self::findPatterns($patternString);

		$replacements = [];
		foreach ($patterns as $patternKey) {
			if (self::isCallbackPattern($patternKey)) {
				$replacement = self::callbackRetrievedStaticFunction($patternKey, $model);
			}

			if (self::isSeparatorPattern($patternKey)) {
				$replacement = self::retrieveSeparator();
			}

			// Replacement retrievals can return null if no replacement can be determined, root those outs.
			if (isset($replacement)) {
				$patternKey = self::addPatternDelimeter($patternKey);
				$replacements[$patternKey] = $replacement;
			}
			unset($replacement);
		}

		// Do the actual replacements.
		$replacedString = (is_array($replacements) && $replacements !== []) ?
			str_replace(array_keys($replacements), array_values($replacements), $patternString) :
			$patternString;

		$replacedString = self::sanitizeReplacedString($replacedString);

		return $replacedString;
	}
24111
public function decorate(array $rules, Model $model = null)
    {
        $this->rules = $rules;
        $this->model = $model;

        $this
            ->replaceTranslationPlaceholders()
            ->replaceKeyPlaceholders();

        return $this->rules;
    }
1277247
public static function ReplaceWithFlags( $arg1, $arg2, $replacement, $flagString )
	{
		$input = $arg1 instanceof Undefined
		    ? ""
		    : $arg1 . "";

		if ( $arg2 instanceof Undefined )
		    throw XPath2Exception::withErrorCodeAndParams( "XPTY0004", Resources::XPTY0004, array( "empty-sequence()", "xs:string in fn:replace" ) );

	    $flagString = ExtFuncs::PrepareRegexFlags( $flagString );
	    $pattern = ExtFuncs::PrepareRegexPattern( $arg2 . "", $flagString );

		if ( ! ExtFuncs::IsValidReplacementString( $replacement ) )
		    throw XPath2Exception::withErrorCodeAndParam( "FORX0004", Resources::FORX0004, $replacement );

		if (  preg_match( "/$pattern/", "" ) )
		{
			throw XPath2Exception::withErrorCodeAndParam( "FORX0003", Resources::FORX0003, $pattern );
		}

		return preg_replace( "/$pattern/$flagString", ExtFuncs::UnescapeReplacementString( $replacement ), $input );
	}
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;
    }
1028727
function matchPatternOrExact(patternStrings, candidate) {
        var patterns = [];
        for (var _i = 0, patternStrings_1 = patternStrings; _i < patternStrings_1.length; _i++) {
            var patternString = patternStrings_1[_i];
            var pattern = tryParsePattern(patternString);
            if (pattern) {
                patterns.push(pattern);
            }
            else if (patternString === candidate) {
                // pattern was matched as is - no need to search further
                return patternString;
            }
        }
        return findBestPatternMatch(patterns, function (_) { return _; }, candidate);
    }
799454
public function setPattern($patternValue) {
		$this->patternValue = $patternValue;
		if (isset($patternValue['patterns'])) {
			foreach ($patternValue['patterns'] as $patternConfiguration) {
				$requestPattern = $this->objectManager->get($this->requestPatternResolver->resolveRequestPatternClass($patternConfiguration['patternType']));
				$requestPattern->setPattern($patternConfiguration['patternValue']);
				$this->subPatterns[] = $requestPattern;
			}
		}
	}
719802
private function replaceModelName($content)
    {
        $newContent = '';
        $content = str_replace('new %modelName%', 'new '.$this->model, $content);
        $content = str_replace('%StaticModelName%', $this->model, $content);
        $content = str_replace('new %StaticModelName%()', $this->model, $content);
        $newContent = str_replace('%modelName%', Inflector::tabilize($this->model), $content);

        return $newContent;
    }
1356229
public function replace($subject)
    {
        if ($this->pattern === null || $this->replace === null) {
            throw new RegexpException("Missing pattern or replacement string regexp replace().");
        }

        return $this->engine->replace($this->pattern, $this->replace, $subject);
    }
38880
public function expr(Model $m, $expr, $args = [])
    {
        if (!is_string($expr)) {
            return $this->connection->expr($expr, $args);
        }
        preg_replace_callback(
            '/\[[a-z0-9_]*\]|{[a-z0-9_]*}/i',
            function ($matches) use (&$args, $m) {
                $identifier = substr($matches[0], 1, -1);
                if ($identifier && !isset($args[$identifier])) {
                    $args[$identifier] = $m->getField($identifier);
                }

                return $matches[0];
            },
            $expr
        );

        return $this->connection->expr($expr, $args);
    }
615852
protected function getRegExpForPattern(string $pattern) : string
    {
        $patternReplaced = str_replace(['*', '?'], ["\nA\n", "\nQ\n"], $pattern);
        $patternReplaced = preg_quote($patternReplaced, '/');
        $patternReplaced = str_replace(["\nA\n", "\nQ\n"], ['.*', '.'], $patternReplaced);

        return '/^' . $patternReplaced . '$/';
    }
486774
public function options(string $pattern, $func)
    {
        if (is_array($func)) {
            if ($this->isPatternMatches($pattern)) {
                $this->middleware = $func['middleware'];
            }
            $func = end($func);
        }

        return $this->match(strtoupper(__FUNCTION__), $pattern, $func);
    }
943207
public function transformPatternToRegex($pattern)
    {
        if (!isset($this->patternToRegexpCache[$pattern])) {
            $this->patternToRegexpCache[$pattern] = $this->transformPatternToRegexWithSupportedPolicy($pattern);
        }

        return $this->patternToRegexpCache[$pattern];
    }
1054070
protected function expandPatterns(array $patterns, $search, array $replacements)
    {
        if ($replacements === []) {
            return $patterns;
        }
        $patternsWithReplacements = [];
        foreach ($patterns as $pattern) {
            foreach ($replacements as $replacement) {
                $patternsWithReplacements[] = Files::getUnixStylePath(str_replace($search, $replacement, $pattern));
            }
        }

        return $patternsWithReplacements;
    }
325567
protected function replace(array &$str, $pattern, $replacement)
    {
        foreach ($str as &$s) {
            $s = preg_replace($pattern, $replacement, $s);
        }
    }
813854
public function replace($patternName, Siteroot $siteroot, ElementVersion $elementVersion, $language)
    {
        if (!isset($this->patterns[$patternName])) {
            $pattern = '%p';
        } else {
            $pattern = $this->patterns[$patternName];
        }

        return $this->replacePattern($pattern, $siteroot, $elementVersion, $language);
    }
917241
public function replace($pattern, $replacement, $flags = 0)
    {

        if ($flags & self::REGEXP) {
            return $this->regexplace($pattern, $replacement);
        } else {
            $function = ($flags & self::CASE_SENSITIVE) ? 'str_replace' : 'str_ireplace';
            $result   = $function($pattern, $replacement, $this->getInternalValue());

        }
        $this->setInternalValue($result);

        return $this;
    }
408567
public function replaceModuleInformation($stub, $modelInformation)
    {
        // replace table
        $stub = str_replace('{{table}}', $modelInformation['table'], $stub);

        // replace fillable
        $this->fieldsHidden = '';
        $this->fieldsFillable = '';
        $this->fieldsCast = '';
        foreach ($modelInformation['fillable'] as $field) {
            // fillable and hidden
            if ($field != 'id') {
                $this->fieldsFillable .= (strlen($this->fieldsFillable) > 0 ? ', ' : '')."'$field'";

                $fieldsFiltered = $this->columns->where('field', $field);
                if ($fieldsFiltered) {
                    // check type
                    switch (strtolower($fieldsFiltered->first()['type'])) {
                        case 'timestamp':
                            $this->fieldsDate .= (strlen($this->fieldsDate) > 0 ? ', ' : '')."'$field'";
                            break;
                        case 'datetime':
                            $this->fieldsDate .= (strlen($this->fieldsDate) > 0 ? ', ' : '')."'$field'";
                            break;
                        case 'date':
                            $this->fieldsDate .= (strlen($this->fieldsDate) > 0 ? ', ' : '')."'$field'";
                            break;
                        case 'tinyint(1)':
                            $this->fieldsCast .= (strlen($this->fieldsCast) > 0 ? ', ' : '')."'$field' => 'boolean'";
                            break;
                    }
                }
            } else {
                if ($field != 'id' && $field != 'created_at' && $field != 'updated_at') {
                    $this->fieldsHidden .= (strlen($this->fieldsHidden) > 0 ? ', ' : '')."'$field'";
                }
            }
        }

        // replace in stub
        $stub = str_replace('{{fillable}}', $this->fieldsFillable, $stub);
        $stub = str_replace('{{hidden}}', $this->fieldsHidden, $stub);
        $stub = str_replace('{{casts}}', $this->fieldsCast, $stub);
        $stub = str_replace('{{dates}}', $this->fieldsDate, $stub);
        $stub = str_replace('{{modelnamespace}}', $this->options['namespace'], $stub);

        return $stub;
    }