【发布时间】:2020-05-20 12:00:36
【问题描述】:
我对正则表达式函数相当陌生。我正在使用 SQL 语法来尝试提取 URL 的某些路径。
网址示例:
https://www.test.com/private/how-to-extract/certain/paths/with-regexp.html
1 2 3 4 5
所以我的第一列应该包括路径 nr 1: private 第二列路径 nr 2: how-to-extract 第三栏:确定 第四列:路径 第五栏:with-regexp
我尝试了以下方法:
,replace(regexp(URL, '(.*?)\/(.*?)', '$2'), '%20', ' ') as path1
,replace(regexp(URL, '(.*?)\/(.*?)\/(.*?)', '$3'), '%20', ' ') as path2
,replace(regexp(URL, '(.*?)\/(.*?)\/(.*?)\/(.*?)', '$4'), '%20', ' ') as path3
,replace(regexp(URL, '(.*?)\/(.*?)\/(.*?)\/(.*?)\/(.*?)', '$5'), '%20', ' ') as path4
,replace(regexp(URL, '(.*?)\/(.*?)\/(.*?)\/(.*?)\/(.*?)\/(.*?)', '$6'), '%20', ' ') as path5
我想我不太明白某些路径的正则表达式函数是如何运作的......
【问题讨论】:
标签: sql regex url path extract