regexp_replace()

If string contains the regex, replaces the matching part with replacement. A set of optional regex options can be set.

Arguments & returns

2 overloads

regexp_replace(string, regex, replacement)

Scalar
Overload link stringregexreplacement Returns
#01 VARCHARVARCHARVARCHAR VARCHAR

regexp_replace(string, regex, replacement, options)

Scalar
Overload link stringregexreplacementoptions Returns
#02 VARCHARVARCHARVARCHARVARCHAR VARCHAR

Example

regexp_replace example
SQL
Haybarn WASM 1.5.5-rc3 · In your browser

Engine example · Run to view results.

In a query

Turn a label into a useful key.

Trim the edges, normalize case, and replace runs of spaces. Small functions compose into a readable cleaning step.

Turn a label into a useful key.
SQL
Haybarn WASM 1.5.5-rc3 · In your browser

Guide recipe · Run to view results.

In other engines

PostgreSQLregexp_replace()

Same function

Exasolregexp_replace()

REGEXP_REPLACE(subject, pattern, replacement, position, occurrence)
In DuckDB
REGEXP_REPLACE(subject, pattern, replacement)

SQLGlot example ↗

Snowflakeregexp_replace()

REGEXP_REPLACE(subject, pattern)
In DuckDB
REGEXP_REPLACE(subject, pattern, '', 'g')

SQLGlot example ↗