> For the complete documentation index, see [llms.txt](https://cgps.gitbook.io/data-flo/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cgps.gitbook.io/data-flo/reference-guide/replace-values-in-columns.md).

# replace-values-in-columns

<mark style="color:purple;">`replace-values-in-columns`</mark> *adaptor replaces all instances of a pattern in one or more columns in a datatable.*

The replacement values can be written to the original columns or new columns.

## Inputs

**`data`**\
Type: `datatable`\
Required: Yes\
The datatable containing values to be replaced.

**`columns`**\
Type: `dictionary`\
Required: Yes\
A dictionary of existing column names with names of new columns, where the dictionary keys are the names of existing columns, and the dictionary values are the names of the columns to which the replacement values are written. If a dictionary value is left blank, the replacement values are written to the original column.

**`pattern`**\
Type: `text`\
Required: Yes\
The text or regular expression to be replaced. The pattern is treated as a regular expression if it begins and ends with `/` (e.g., `/.*/`).

**`replacement`**\
Type: `text`\
Required: No\
The text that replaces all instances of the `pattern`. If unspecified, matches will be replaced with blank text. If a regular expression was used as a pattern, capture groups can be included as `$1`, `$2`, etc.

## Outputs

**`data`**\
Type: `datatable`\
A datatable with replacement values written to the original columns or new columns.

## Examples

### Example 1: Default behaviour.

Inputs:

`data`:

| id | code | name           |
| -- | ---- | -------------- |
| 1  | GB   | United Kingdom |
| 2  | TR   | Turkey         |
| 3  | US   | United States  |
| 4  | IND  | India          |

`columns`:

| KEY  | VALUE |
| ---- | ----- |
| code |       |

`pattern`: GB

`replacement`: UK

#### Outputs:

`list`:

| id | code | name           |
| -- | ---- | -------------- |
| 1  | UK   | United Kingdom |
| 2  | TR   | Turkey         |
| 3  | US   | United States  |
| 4  | IND  | India          |

-> Replaced the value `GB` in the existing `code` column with the value `UK`.
