# Replace in String

The Replace in string step performs a simple search and replace. This step supports regular expressions and group references. Group references are shown in the **Replace with** column as `$n`, where `n` is the number of the group.

### Step name

Enter the following information in the transformation step field:

* **Step name**: Specify the unique name of the step on the canvas. The default is Replace in string. You can customize the name or leave it as the default.

### Fields string table

![Fields string table in Replace in string](/spaces/YwnJ6Fexn4LZwKRHghPK/files/hTfNT8Iu9SC3tV5me2As)

Use the following table to specify the replacement string and related options.

| Column                 | Description                                                                                                              |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| **In stream field**    | Specify the field to replace from the PDI input stream. Click **Get Fields** to add all fields from the input stream(s). |
| **Out stream field**   | Specify the new field name to output to the PDI stream.                                                                  |
| **Use RegEx**          | Select **Y** or **N** to indicate whether to use a regular expression to search for values.                              |
| **Search**             | Specify the string to search for.                                                                                        |
| **Replace with**       | Specify the string to replace the matched value.                                                                         |
| **Set empty string?**  | Select **Y** or **N** to indicate whether to replace null values with empty strings.                                     |
| **Replace with field** | Specify a field value to use as the replacement value.                                                                   |
| **Whole word**         | Select **Y** or **N** to indicate whether to replace the entire word of the matched value.                               |
| **Case sensitive**     | Select **Y** or **N** to indicate whether the search is case sensitive.                                                  |
| **Is Unicode**         | Select **Y** or **N** to indicate whether the search value is a sequence of Unicode characters.                          |

You can click **Get Fields** to add all fields from the PDI input stream.

### Example: Use regular expression group references

When using regex (regular expression) group references, matching patterns are represented by a sequence of integer values with a dollar sign prefix. For example, `$1` for the first group match, `$2` for the second group match, and so forth.

To replace a portion of the incoming value contained in **In stream field**, use a group value token to represent the portion of the string that the group matched.

For example, suppose the string value of **In stream field** is `Homer Simpson`.

To switch the first and last name:

1. Set **Use RegEx** to `Y`.
2. Set **Search** to `/([a-zA-Z]*) ([a-zA-Z]*)/`.

   Each pattern inside parentheses represents a group, so `$1` = `Homer` and `$2` = `Simpson`.

   ![Regular expression group example](/spaces/YwnJ6Fexn4LZwKRHghPK/files/2fQsoDKYbndxX8t6GG76)
3. Set **Replace with** to `$2 $1`.

   This places `Simpson` first, followed by `Homer`.

For more information about regular expressions, see <https://www.regular-expressions.info/brackets.html>.

### Metadata injection support

All fields of this step support metadata injection. You can use this step with [ETL metadata injection](/pdia-data-integration/pdi-transformation-steps-reference-overview/etl-metadata-injection.md) to pass metadata to your transformation at runtime.

### See also

* [Regex Evaluation](/pdia-data-integration/pdi-transformation-steps-reference-overview/regex-evaluation.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.pentaho.com/pdia-data-integration/pdi-transformation-steps-reference-overview/replace-in-string.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
