使用正则表达式逐段获取字符串路径(SQL -Athena)

getting the string path piece by piece with regex (SQL -Athena)

我想在 Amazon AthenaSQL 中将字符串转换为行

由于 Athena 不支持某些功能,我被迫执行许多正则表达式功能

一个输入(也可以有不同的长度)可以是这样的:

v1 facility username utm_parameter

我想把它变成一个 table 看起来像这样的人

1st    |  2nd     | 3rd     | 4th
------ | ------   | -----   | -----
v1     | facility |username | utm_parameter

我已经用这段代码过滤掉字符串中的第一段文本:

SELECT REGEXP_EXTRACT( REGEXP_replace( REGEXP_REPLACE( REGEXP_EXTRACT( REGEXP_EXTRACT(message,'path=\S+'),'"(.*?)"'),'/', ' '),'"',''),'\S+') AS '1st' from data

但我不知道如何使用正则表达式获取下一个空格后的文本部分

有谁知道我如何编写下一个正则表达式函数?

试试这个:

-- input, don't use in real query
WITH
input(message) AS (
SELECT 'v1 facility username utm_parameter'
)
-- input end, start real query here
SELECT
  SPLIT_PART(message,' ',1) AS "1st"
, SPLIT_PART(message,' ',2) AS "2nd"
, SPLIT_PART(message,' ',3) AS "3rd"
, SPLIT_PART(message,' ',4) AS "4th"
FROM input;

1st|2nd     |3rd     |4th
v1 |facility|username|utm_parameter

此外,这就像拼写密西西比这个词:你需要知道什么时候停止......