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 transformpatternthe regular expression sourcereplacementthe replacement, with \0..\9 group referencesExample
program Demo {
entry {
print(Regex.replace("hi {name}!", "\\{(\\w+)\\}", "[\\1]"))
}
}