我正在尝试了解正则表达式,并且正在尝试使用 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 中使用正则表达式函数实现相同的目的?
您的括号转义错误,请使用单个
\
:
select regexp_replace('iphone-ios-cx 12.45.0(2144)', '\(.*\)','');
输出:
_col0
-----------------------
iphone-ios-cx 12.45.0