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

# REGEXP_REPLACE

> Replaces every regular-expression match in a string.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Scalar function</span></div>

NULL value, pattern, or replacement returns NULL. A constant NULL position uses position 1.

## Syntax

### Scalar

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
regexp_replace(value, pattern [, replacement [, position]])
```

## Arguments

| Name | Type | Required | Description |
| - | - | - | - |
| value | STRING | Yes | The string to transform. |
| pattern | STRING | Yes | The regular expression. |
| replacement | STRING | No | The replacement text. Default: ''. |
| position | INTEGER | No | The 1-based character position where matching begins. Use a positive integer literal. Must be a constant argument. Default: 1. |

## Returns

* Type: STRING
* Possible values: The string with all matches at or after position replaced.
* NULL behavior: NULL value, pattern, or replacement returns NULL. A constant NULL position uses position 1.

## Properties

| Property | Value |
| - | - |
| Deterministic | Yes |
| Supports window usage | No |
| Exact result | Yes |

## Usage notes

* Characters before position are retained unchanged. Replacements support capture references such as \$1 and backslash-1.
* Position zero or one replaces from the beginning. A larger position counts Unicode characters, preserves the preceding prefix, and leaves the string unchanged if beyond the end. Pattern and replacement columns are handled per row in the generic path.

## Examples

### Typical behavior

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT regexp_replace('a1b2', '[0-9]', 'X') AS replaced, regexp_replace('a1b2', '[0-9]') AS removed;
```

| replaced | removed |
| - | - |
| aXbX | ab |

### Omitted replacement removes matches

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT regexp_replace('a1b2', '[0-9]') AS letters;
```

| letters |
| - |
| ab |

## Limitations

* Position is used only when it is a constant integer. A position column or constant NULL uses position 1. Negative constant positions normally leave the string unchanged.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.