REGEXP_REPLACE

The REGEXP_REPLACE function finds and replaces text column substrings using constant regexp-based patterns with constant replacement strings.

For related information, see the following:

Syntax

REGEXP_REPLACE(input, pattern [, replacement [, position [, occurrence]]])

Arguments

The following table shows the REGEXP_REPLACE arguments:

Parameter

Description

input

The replaced input value.

pattern

The pattern that identifies which substrings to replace.

replacement

The replacement string.

position

Indicates the 1-based offset where the pattern search starts.

occurrence

(Optional) Sets a specific occurrence to replace. Using 0 replaces all occurrences.

Supported RegEx Patterns

Returns

The REGEXP_REPLACE function returns the replaced input value.

Notes

The test pattern must be a literal string.

Example

CREATE TABLE test(country_name TEXT);
INSERT INTO test values('SWEDEN');
SELECT REGEXP_REPLACE(country_name, 'WEDE', 'PAI') FROM test;

Output:

country_name|
------------+
SPAIN       |