---
title: "regexp_replace function in Strata | Oplema"
description: "Replace the first match of a regular expression in text. For example, regexp_replace('hello', '[lo]', '-') returns 'he-lo'."
url: "https://oplema.com/docs/strata/functions/regexp-replace"
updated: "2026-11-04"
---

# regexp\_replace

Replace the first match of a regular expression in text. Pass the g option to replace every match.

## Try an expression

In [Formula](https://oplema.com/docs/strata/prep/formula), enter the expression and set Output type to **VARCHAR**.

### Expression

```
regexp_replace('hello', '[lo]', '-')
```

### Result

```
'he-lo'
```

To use your own data, replace the example values with column names. Keep format strings and other options as written.

Try it live in Formula

Result
| id | result |
| --- | --- |
| 1 | he-lo |

## Arguments and types

```
regexp_replace(string, regex, replacement, options)
```

**string**

Text

**regex**

Text

**replacement**

Text

**options**

Text

Supported signatures (2)

```
regexp_replace(string: VARCHAR, regex: VARCHAR, replacement: VARCHAR) → VARCHAR
regexp_replace(string: VARCHAR, regex: VARCHAR, replacement: VARCHAR, options: VARCHAR) → VARCHAR
```

The result type can depend on the input types. See DuckDB for the full argument rules.

## Things to know

Only the first match is replaced by default. Add the fourth argument 'g' to replace every match.

If the first argument is missing, the result is NULL.

### Replace every match

```
regexp_replace('hello', '[lo]', '-', 'g')
```

'he---'

## Related functions

[replace

Replace every occurrence of one piece of text with another.

](https://oplema.com/docs/strata/functions/replace)[regexp\_extract

Return the part of text that matches a regular expression, or empty text if there is no match. An optional constant group number picks a capturing group, and regex options can follow.

](https://oplema.com/docs/strata/functions/regexp-extract)[regexp\_matches

Check whether text contains a match for a regular expression. An optional argument sets regex options.

](https://oplema.com/docs/strata/functions/regexp-matches)[regexp\_split\_to\_array

Split text at each match of a regular expression and return the parts as a list. An optional argument sets regex options.

](https://oplema.com/docs/strata/functions/regexp-split-to-array)

[Browse patterns](https://oplema.com/docs/strata/functions#patterns) [DuckDB documentation](https://duckdb.org/docs/current/sql/functions/regular_expressions.html#regexp_replacestring-pattern-replacement-options)

Function metadata from DuckDB, used under the [MIT license](https://github.com/duckdb/duckdb/blob/v1.5.4/LICENSE).
