【问题标题】:Regexp to extract paths between slashes in a long URL正则表达式提取长 URL 中斜杠之间的路径
【发布时间】: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


    【解决方案1】:

    最好使用INSTR 函数,它可以获取n 次出现的子字符串。

    INSTR( string, substring [, start_position [, nth_appearance ] ] )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-07
      • 1970-01-01
      相关资源
      最近更新 更多