# REGEXP_REPLACE

> StackQL 中的 REGEXP_REPLACE 函式：將字串中符合正規表示式的部分取代為取代字串。

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

將相符的子字串取代為取代字串。  

另請參閱：  
[[` SELECT `]](/language-spec/select) [[ 正規表示式參考 ]](/language-spec/functions/re/reference) 

* * * 

## 語法

```sql
SELECT REGEXP_REPLACE(source, pattern, replacement) FROM <multipartIdentifier>;
```
## 引數

__*source*__  
字串常值或字串資料行，其中符合正規表示式 `pattern` 的部分會取代為 `replacement`。  

__*pattern*__  
要搜尋的正規表示式模式。  

__*replacement*__  
取代字串。

> 取代字串中支援對擷取群組 `\1` 到 `\9` 的反向參考。  

## 傳回值
傳回字串。

* * *

## 範例

### 取代資料行中的正規表示式模式

**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';
```

**結果**

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

如需詳細資訊，請參閱 [https://github.com/nalgeon/sqlean/blob/main/docs/re.md](https://github.com/nalgeon/sqlean/blob/main/docs/re.md)。
