SELECT split(split(t.col, '\\|')[0],'\\:')[1] AS ID,
split(split(t.col, '\\|')[1], '\\:')[1] AS Value,
split(split(t.col, '\\|')[2], '\\:')[1] AS Name
FROM (SELECT 'ID(1001):10|Value(1002):8|Name(xyz):7' AS col) t;
+-----+--------+-------+--+
| id | value | name |
+-----+--------+-------+--+
| 10 | 8 | 7 |
+-----+--------+-------+--+
select m['ID'] as id, m['Value'] as value, m['Name'] as Name
from (select str_to_map(regexp_replace('ID(1001):10|Value(1002):8|Name(xyz):7','\\(.*?\\)',''),'\\|',':') as m
)s;
结果:
id value name
10 8 7
仅使用regexp:
SELECT regexp_extract(t.col,'(?i)ID.*?:(\\d+)\\|',1) as ID,
regexp_extract(t.col,'(?i)Value.*?:(.?+)\\|',1) as Value,
regexp_extract(t.col,'(?i)Name.*?:(.?+)\\|*',1) as Name
FROM (SELECT 'ID(1001):10|Value(1002):8|Name(xyz):7' AS col) t;
2条答案
按热度按时间6pp0gazn1#
如果你能用
SPLIT
功能,这将是非常容易的。例如:2skhul332#
删除括号中的字符串,转换为map并使用map['key']获取字段:
结果:
仅使用regexp:
结果: