Skip to content

Replaces literal substrings within a string.

replace(x:string, pattern:string, replacement:string, [max=int], [ignore_case=bool]) -> string

The replace function returns a new string where occurrences of pattern in x are replaced with replacement, up to max times. If max is omitted, all occurrences are replaced.

Set ignore_case=true to match using full Unicode case folding instead of case-sensitive matching.

The subject to replace the action on.

The pattern to replace in x.

The replacement value for pattern.

The maximum number of replacements to perform.

If the option is not set, all occurrences are replaced.

If true, matches the literal pattern using full Unicode case folding.

Defaults to false.

from {x: "hello".replace("l", "r")}
{x: "herro"}
from {x: "hello".replace("l", "r", max=1)}
{x: "herlo"}
from {
ascii: "Connection ERROR".replace("error", "warning", ignore_case=true),
unicode: "Fußstraße".replace("STRASSE", "weg", ignore_case=true),
}
{
ascii: "Connection warning",
unicode: "Fußweg",
}

Last updated: