> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bringits.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Regex

> Apply regex operations on strings or arrays within a data source

The Regex command (Command Type: 1009) applies regex operations on strings or arrays within a data source. It supports the standard JavaScript regex methods: `match`, `matchAll`, `search`, `replace`, and `replaceAll`.

## Overview

The Regex command provides functionality for:

* Matching patterns in string fields
* Replacing substrings using regex patterns
* Searching for pattern occurrences
* Applying flags like `g`, `i`, `m`, `u`, `s` for fine-grained control

## Command Type

**Command Type ID:** 1009

## Parameters

| Parameter        | Type   | Description                                                                                                  | Required |
| ---------------- | ------ | ------------------------------------------------------------------------------------------------------------ | -------- |
| **methodName**   | string | The regex method to apply. Possible values: `"match"`, `"matchAll"`, `"search"`, `"replace"`, `"replaceAll"` | Yes      |
| **pattern**      | string | The regex pattern to apply                                                                                   | Yes      |
| **flag**         | string | Optional regex flags (e.g. `g`, `i`, `m`, `u`, `s`)                                                          | No       |
| **replaceValue** | string | The replacement value for `replace` or `replaceAll` methods                                                  | No       |
| **source**       | string | The key in the data source to apply the regex on. If not provided, operates directly on the data             | No       |

## Usage Examples

### Match a Pattern

```json theme={null}
{
  "command": "regex",
  "params": {
    "methodName": "match",
    "pattern": "\\d+",
    "source": "rawText"
  }
}
```

### Replace a Substring

```json theme={null}
{
  "command": "regex",
  "params": {
    "methodName": "replace",
    "pattern": "\\s+",
    "replaceValue": "_",
    "source": "name"
  }
}
```

### Replace All Occurrences

```json theme={null}
{
  "command": "regex",
  "params": {
    "methodName": "replaceAll",
    "pattern": ",",
    "replaceValue": ".",
    "source": "priceString"
  }
}
```

### Case-Insensitive Match

```json theme={null}
{
  "command": "regex",
  "params": {
    "methodName": "match",
    "pattern": "error",
    "flag": "i",
    "source": "message"
  }
}
```

## Supported Methods

| Method       | Description                                  |
| ------------ | -------------------------------------------- |
| `match`      | Returns the first match of the pattern       |
| `matchAll`   | Returns all matches of the pattern           |
| `search`     | Returns the index of the first match         |
| `replace`    | Replaces the first match with `replaceValue` |
| `replaceAll` | Replaces all matches with `replaceValue`     |

## Common Use Cases

* **Data Cleaning**: Remove or replace unwanted characters from string fields
* **Pattern Extraction**: Extract numeric IDs, codes, or tokens from raw text
* **Normalization**: Standardize formats (e.g. date strings, phone numbers)

## Related Commands

* [String Manipulation](/stream/commands/parse/string-manipulation) - Apply JS string methods to fields
* [String Split](/stream/commands/parse/string-split) - Split strings by a delimiter
* [Filter](/stream/commands/parse/filter) - Filter objects after regex extraction
