# REGEXP_REPLACE

> REGEXP_REPLACE function in StackQL: replace the parts of a string that match a regular expression with a replacement string.

Source: https://stackql.io/language-spec/functions/re/regexp_replace

Replaces a matching substring with replacement string.  

See also:  
[[` SELECT `]](/language-spec/select) [[ Regular Expression Reference ]](/language-spec/functions/re/reference) 

* * * 

## Syntax

```sql
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

**StackQL**

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

**Results**

```
|------|--------------|
| name | date_created |
|------|--------------|
| vm0  | 2022-09-14   |
|------|--------------|
| vm1  | 2022-09-14   |
|------|--------------|
| vm2  | 2022-09-14   |
|------|--------------|
```

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