翻译页面
本页面由 AI 辅助从英文翻译而来。如两者存在差异,以英文版本为准。
REGEXP_REPLACE
将匹配的子字符串替换为替换字符串。
另请参阅:
[SELECT] [ 正则表达式参考 ]
语法
SELECT REGEXP_REPLACE(source, pattern, replacement) FROM <multipartIdentifier>;
参数
source
字符串字面量或字符串列,其中与正则表达式 pattern 匹配的部分会被替换为 replacement。
pattern
要搜索的正则表达式模式。
replacement
替换字符串。
替换字符串按原样插入:
$1等捕获组引用不会被展开。
返回值
返回一个字符串。
示例
替换列中的正则表达式模式
- StackQL
- 结果
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/google/re2/wiki/Syntax