使用 regexp_extract 从配置单元中的字符串中提取文本

问题描述

在我的示例中,如何从 even_list 列中提取 '705=' 和下一个逗号之间的数字?

enter image description here

解决方法

请在 hive 中使用 split
首先,我们将使用 705= 作为分隔符来分割数据。
然后再次使用 split 以逗号分隔。这给了我想要的结果。

select  split(split('123705=35,4,6752,56','705=')[1],',')[0] col 
output
35

enter image description here

,

使用正则表达式:

select regexp_extract(event_list,'705=([0-9.]+)',1) 

或者您可以使用带逗号的更严格的正则表达式 ',705=([0-9.]+),'