在 Athena 中使用正则表达式提取括号前的字符串值

问题描述 投票:0回答:1

我正在尝试了解正则表达式,并且正在尝试使用 regexp_extract 提取开括号字符之前的数据。

字符串值:

设备
iphone-ios-cx 12.45.0(2144)

预期输出:

设备
iphone-ios-cx 12.45.0

我可以使用 split_part 函数来实现这一点。

select split_part(device, '(', 1)
FROM devices_tbl

我使用 regexp_replace 和 regexp_extract 尝试了相同的操作,两者似乎都给了我不正确的结果

select regexp_replace(device, '\\(.*\\)','')
FROM devices_tbl

如何在 Athena 中使用正则表达式函数实现相同的目的?

sql amazon-athena presto trino
1个回答
0
投票

您的括号转义错误,请使用单个

\
:

select regexp_replace('iphone-ios-cx 12.45.0(2144)', '\(.*\)','');

输出:

         _col0         
-----------------------
 iphone-ios-cx 12.45.0 
© www.soinside.com 2019 - 2024. All rights reserved.