Skip to main content

REGEXP_REPLACE

Replaces a matching substring with replacement string.

See also:
[SELECT] [ Regular Expression Reference ]


Syntax

SELECT REGEXP_REPLACE(source, pattern, replacement) FROM <multipartIdentifier>;

Arguments

source
A literal string or string column from which you want to extract a substring based upon a pattern defined by a regular expression (pattern).

pattern
The regular expression pattern to search for.

replacement
The replacement string.

Supports backreferences to captured groups \1 through \9 in replacement string.

Return Value(s)

Returns a string.


Examples

Replace a regular expression pattern in a column

select name,
regexp_replace(json_extract(properties, '$.timeCreated'), 'T.*', '') as date_created
from azure.compute.virtual_machines
WHERE subscriptionId = '273769f6-545f-45b2-8ab8-2f14ec5768dc';

For more information, see https://github.com/nalgeon/sqlean/blob/main/docs/re.md