API Reference › Regex › Regex.replace
method

Regex.replace

Regex.replace(text, pattern, replacement) -> string

Returns a new string with every non-overlapping match of pattern in text replaced by replacement. In the replacement, \0 is the whole match, \1…\9 are capture groups, and \\ is a literal backslash — the natural fit for dialogue/localization token substitution.

Parameters

textthe string to transform
patternthe regular expression source
replacementthe replacement, with \0..\9 group references

Example

program Demo {
  entry {
    print(Regex.replace("hi {name}!", "\\{(\\w+)\\}", "[\\1]"))
  }
}
← All symbols