# Example: Using 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 the **In stream field** column, use one of the group value tokens to represent the portion of the string that group matched.

As an example, suppose the string value of **In stream field** is: `Homer Simpson`

To switch the first and last name, you would set up the table fields as follows:

1. Set the **use RegEx** column to: **Y**
2. The value of the **Search** column would look similar to: `/([a-zA-Z]*) ([a-zA-Z]*)/`

   Each pattern inside the parenthesis represents a grouping, so that now **$1** = `Homer` and **$2** = `Simpson`

   ![Regular expression group example](/files/E2QE8xBpjtKO46kNmhpN)
3. To switch the first and last name, set the value of the **Replace with** field as: `$2 $1`

   This places the string `Simpson` first, followed by `Homer` second.

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


---

# 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/10.2-data-integration/pdi-transformation-steps-reference-overview/replace-in-string/example-using-regular-expression-group-references.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.
