RegexReplace

Category: Script / Strings
Since engine version: 8.0 OC

Description

Returns a string in which all regular expression matches are replaced by a replacement string.

Syntax

string RegexReplace(string text, string regex, string replacement, int flags);

Parameters

text:
Source string in which the replacements occur.
regex:
Regular expression in ECMAScript syntax
replacement:
New substring by which the regular expression matches will be replaced. Can reference submatches with $1, $2 etc.
flags:
Bitmask of the following values:
Constant Description
Regex_CaseInsensitive Regular expression is case insensitive.
Regex_FirstOnly Only replace the first match instead of all matches.

Example

Log(RegexReplace("hello world", "(\\w+)\\s(\\w+)", "$2 $1"));
Swaps two words, displaying "world hello".
See also: RegexMatch, RegexSearch, RegexSplit, ReplaceString
Luchs, 2016-09