> For the complete documentation index, see [llms.txt](https://docs.kognitos.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kognitos.com/legacy/legacy-experience/automation-areas/text/removal/remove-text-using-regex.md).

# Remove Text Using Regex

## Overview

This operation lets you clean a text by removing all or specific occurrences of a regular expression pattern. You can optionally define the strategy to either remove the first occurrence, the last occurrence, or all occurrences of the matched pattern in the text.

## Syntax

This operation supports both of the following syntaxes:

#### Option 1

This syntax defines **the text** as data.

```
the text is "{input}"
the regular expression is "{regex}"
remove the regular expression from the text
 the remove strategy is "{strategy}"
```

#### Option 2

```
the regular expression is "{regex}"
remove the regular expression from "{input}"
 the remove strategy is "{strategy}"
```

> **Note:** Specifying a remove strategy is optional. By default, all matching occurrences are removed.

## 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 regular expression | No             |
| the remove 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.

<table data-header-hidden><thead><tr><th width="140.07421875">Parameter</th><th width="227.63671875">Description</th><th width="243.33203125">Examples</th><th>Required</th></tr></thead><tbody><tr><td><code>input</code></td><td>The text to be cleaned.</td><td>The order number is 12345.</td><td>Yes</td></tr><tr><td><code>regex</code></td><td>The regular expression pattern to be removed.</td><td>[0-9]+</td><td>Yes</td></tr><tr><td><code>strategy</code></td><td><p>The removal strategy. Accepted Values:</p><ul><li><strong>first</strong> - Removes the first occurrence.</li><li><strong>last</strong> - Removes the last occurrence.</li><li><strong>all</strong> - Removes all occurrences. <em>(default)</em></li></ul></td><td>all</td><td>Optional</td></tr></tbody></table>

## Examples

### 1. No removal strategy specified

In this example, no removal strategy is specified, so all matching occurrences are removed by default.

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

```
the regular expression is "[0-9]+"
remove the regular expression from "The order number is 12345."
```

{% endtab %}

{% tab title="Results" %}

```
The order number is .
```

{% endtab %}
{% endtabs %}

### 2. Removing the first occurrence

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

```
the text is "The order number is 12345, and the reference ID is 67890."
the regular expression is "[0-9]+"
remove the regular expression from the text
  the remove strategy is "first"
```

{% endtab %}

{% tab title="Results" %}

```
The order number is , and the reference ID is 67890.
```

{% endtab %}
{% endtabs %}

### 3. Removing the last occurrence

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

```
the text is "The order number is 12345, and the reference ID is 67890."
the regular expression is "[0-9]+"
remove the regular expression from the text
  the remove strategy is "last"
```

{% endtab %}

{% tab title="Results" %}

```
The order number is 12345, and the reference ID is .
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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.kognitos.com/legacy/legacy-experience/automation-areas/text/removal/remove-text-using-regex.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.
