sql - SQL - 在正则表达式之后获取第三个字符串
问题描述
所以例如我有这个数据:
rmchat://room/kotak.com/Kotak_Debt_Brokers
我只需要从字符串中获取“Kotak”并将其显示在另一列中。有没有办法得到它?我一直在网上搜索,我似乎无法找到解决方案。请帮我。
STR, REGEXP_SUBSTR(STR, '(.*?)(\/||$)', 1, 2, NULL, 1)
这是我当前的代码,但它输出的最后一个字符串是 Kotak_Debt_Brokers。
解决方案
利用
REGEXP_SUBSTR(STR, '.*/([^_]+)', 1, 1, NULL, 1)
或者,或者,
REGEXP_REPLACE(STR, '.*/([^_]+).*', '\\1')
请参阅正则表达式证明/正则表达式证明 ( regexp_replace
)。
解释
--------------------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
/ '/'
--------------------------------------------------------------------------------
( group and capture to \1:
--------------------------------------------------------------------------------
[^_]+ any character except: '_' (1 or more
times (matching the most amount
possible))
--------------------------------------------------------------------------------
) end of \1
--------------------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
推荐阅读
- node.js - 如何使用弹性搜索中的脚本获取特定给定范围内的趋势?
- java - java.net HttpURLConnection 内容类型不匹配
- reactjs - 功能组件是否会导致内存问题?
- string - 如何使用 PySpark 拆分字符串数据并在表中加载数据
- android - 我可以从应用程序调用授予权限 ADB 命令吗
- github - 我在谷歌搜索中找不到我的 github 帐户
- pandas - pandas:如何使用 predict_proba 获取每个客户的概率
- oracle - 什么是预言机事件记录?
- laravel - 在 Lumen 包开发中未触发包级 Composer
- java - 在 Java 编译时生成枚举