我的数据是URL
https://www.stackoverflow.com/abc/sometihng-herer?&jhdsfj@38736
我正在寻找的输出是从第三次出现"/"到"?"之前
样本输出:
/abc/sometihng-herer
数据库为vertical,数据类型为长字符
我们可以在这里使用regex子字符串方法:
SELECT url, REGEXP_SUBSTR(url, 'https?://[^/]+(/[^?]+)', 1, 1, '', 1) AS path
FROM yourTable;
下面是一个regex演示,显示了该逻辑正在工作。
您也可以使用SPLIT_PART
,一次使用斜线,一次用问号:
WITH
indata(url) AS (
SELECT 'https://www.stackoverflow.com/abc/sometihng-herer?&jhdsfj@38736'
)
SELECT
SPLIT_PART(url,'/',5) AS sp5 -- it is the fifth slash-delimited token of the url
, SPLIT_PART(sp5,'?',1) AS whatwewant
FROM indata;
-- out sp5 | whatwewant
-- out -------------------------------+-----------------
-- out sometihng-herer?&jhdsfj@38736 | sometihng-herer