---
id: regex-replace
name: Regex.replace
category: regex
kind: namespace-method
tokens: Regex.replace
sig: Regex.replace(text, pattern, replacement) -> string
tip: Replace every match; the replacement expands \0..\9 group references.
order: 8
ns: Regex
member: replace
---
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:
- `text` — the string to transform
- `pattern` — the regular expression source
- `replacement` — the replacement, with `\0`..`\9` group references
```ludic
program Demo {
entry {
print(Regex.replace("hi {name}!", "\\{(\\w+)\\}", "[\\1]"))
}
}
```