# Replace Text

## Overview

This operation lets you replace occurrences of a specific text with a new text. For instance, consider the following sentence:

> The dog jumped over the curb and then the dog sprinted away.

Using this operation, you can replace all instances of **dog** with **cat**, resulting in:

> The cat jumped over the curb and then the cat sprinted away.

## Syntax

This operation supports both of the following syntaxes:

#### Option 1

```
the text is "{input}"
replace "{substring}" with "{replacement}" in the text
  the replacement strategy is "{strategy}"
```

#### Option 2

```
the text is "{input}"
replace "{substring}" in the text where
    the replacement is "{replacement}"
    the replacement strategy is "{strategy}"
```

> **Note:** Specifying **the replacement strategy** is **optional.** By default, all occurrences are replaced.

## Data

The table below lists the names of the data elements in this operation and indicates which can be renamed in the syntax.

| Data Name                | Can Be Renamed |
| ------------------------ | -------------- |
| the text                 | Yes            |
| the replacement strategy | No             |

## Parameters

**Parameters** are placeholders for data. Refer to the table below for details on each parameter in this operation. In the syntax, replace parameters with your own values.

| Parameters    | Description                                                                                                                                                                                                                                                                               | Examples                                                     | Required |
| ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------ | -------- |
| `input`       | The input text where replacements will occur.                                                                                                                                                                                                                                             | The dog jumped over the curb and then the dog sprinted away. | Yes      |
| `substring`   | The section of the text to be replaced.                                                                                                                                                                                                                                                   | dog                                                          | Yes      |
| `replacement` | The replacement value.                                                                                                                                                                                                                                                                    | cat                                                          | Yes      |
| `strategy`    | <p>The method for replacing matches of the substring. Accepted values:</p><ul><li><strong>first</strong>- Removes the first occurrence. <em>(default)</em></li><li><strong>last</strong> - Removes the last occurrence.</li><li><strong>all</strong> - Removes all occurrences.</li></ul> | all                                                          | Optional |

## Examples

### 1. Replace all occurrences

{% tabs %}
{% tab title="Automation" %}

```
the text is "The dog jumped over the curb and then the dog sprinted away."
replace "dog" with "cat" in the text
```

{% endtab %}

{% tab title="Results" %}

```
The cat jumped over the curb and then the cat sprinted away.
```

{% endtab %}
{% endtabs %}

### 2. Replace the first occurrence

{% tabs %}
{% tab title="Automation" %}

```
the text is "The dog jumped over the curb and then the dog sprinted away."
replace "dog" with "cat" in the text
  the replacement strategy is "first"
```

{% endtab %}

{% tab title="Results" %}

```
The cat jumped over the curb and then the dog sprinted away.
```

{% endtab %}
{% endtabs %}
