# Function: replace() (/jsdoc/pixi-vn-ink/index/namespaces/TextReplaces/functions/replace)



\> **replace**(`text`, `replaceOptions`): `string`

Defined in: node\_modules/@drincs/pixi-vn-json/dist/index.d.ts:1244

Applies all registered handlers of the specified type to the given text in order.

For each handler:

1. All `[key]` tokens currently present in the text are collected.
2. For each unique key, the handler's `validation` is tested against the key.
3. If validation passes, the handler is called with the key.
4. If the handler returns a string, **all** occurrences of `[key]` in the text are
   replaced with that string.
5. After the handler has processed all tokens, the next handler starts on the updated text.

Parameters [#parameters]

text [#text]

`string`

The source text to process.

replaceOptions [#replaceoptions]

Specifies which phase of handlers to run.

type [#type]

`"before-translation"` | `"after-translation"`

Which phase of handlers to execute.

Returns [#returns]

`string`

The text after all matching handlers have been applied.

Example [#example]

```ts
// Given handlers that replace [name] -> "Mario" and [surname] -> "Rossi":
TextReplaces.replace("Ciao [name] [surname]. [name] vai pure", { type: "before-translation" })
// => "Ciao Mario Rossi. Mario vai pure"
```
