翻译页面
本页面由 AI 辅助从英文翻译而来。如两者存在差异,以英文版本为准。
REGEXP_SUBSTR
从输入字符串中返回与指定模式匹配的子字符串。
另请参阅:
[SELECT] [ 正则表达式参考 ]
语法
SELECT REGEXP_SUBSTR(source, pattern) FROM <multipartIdentifier>;
参数
source
要根据由正则表达式(pattern)定义的模式从中提取子字符串的字符串字面量或字符串列。
pattern
要搜索的正则表达式模式。
返回值
返回一个字符串。
示例
根据正则表达式提取子字符串
- StackQL
- 结果
select name,
json_extract(properties, '$.storageProfile.imageReference.offer') as os,
regexp_substr(
json_extract(properties, '$.storageProfile.imageReference.exactVersion'),
'[0-9][0-9]\.[0-9][0-9]') as os_version
from azure.compute.virtual_machines
WHERE subscription_id = '273769f6-545f-45b2-8ab8-2f14ec5768dc';
|------|---------------|------------|
| name | os | os_version |
|------|---------------|------------|
| vm0 | UbuntuServer | 16.04 |
|------|---------------|------------|
| vm1 | UbuntuServer | 16.04 |
|------|---------------|------------|
| vm2 | UbuntuServer | 20.04 |
|------|---------------|------------|
有关更多信息,请参阅 https://github.com/nalgeon/sqlean/blob/main/docs/re.md