跳至主要內容
翻譯頁面

本頁面由英文在 AI 協助下翻譯而成。若兩者有出入,請以英文版本為準。

REGEXP_REPLACE

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

另請參閱:
[SELECT] [ 正規表示式參考 ]


語法​

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

引數​

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

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

replacement
取代字串。

取代字串會依原樣插入:不會展開 $1 等擷取群組參考。

傳回值​

傳回字串。


範例​

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

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

如需詳細資訊,請參閱 https://github.com/google/re2/wiki/Syntax。