regexp用于在长url中提取斜杠之间的路径

h7appiyu  于 2021-08-09  发布在  Java
关注(0)|答案(1)|浏览(442)

我对regexp函数相当陌生。我正在使用sql语法尝试提取url的某些路径。
url示例:

  1. https://www.test.com/private/how-to-extract/certain/paths/with-regexp.html
  2. 1 2 3 4 5

因此,我的第一列应该包括路径nr1:private第二列路径nr2:how to extract third column:some fourth column:paths fifth column:with regexp
我尝试了以下方法:

  1. ,replace(regexp(URL, '(.*?)\/(.*?)', '$2'), '%20', ' ') as path1
  2. ,replace(regexp(URL, '(.*?)\/(.*?)\/(.*?)', '$3'), '%20', ' ') as path2
  3. ,replace(regexp(URL, '(.*?)\/(.*?)\/(.*?)\/(.*?)', '$4'), '%20', ' ') as path3
  4. ,replace(regexp(URL, '(.*?)\/(.*?)\/(.*?)\/(.*?)\/(.*?)', '$5'), '%20', ' ') as path4
  5. ,replace(regexp(URL, '(.*?)\/(.*?)\/(.*?)\/(.*?)\/(.*?)\/(.*?)', '$6'), '%20', ' ') as path5

我想我不太明白某些路径的regexp函数是如何运行的。。。

aiazj4mn

aiazj4mn1#

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

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

相关问题