微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Hive 类似匹配词边界

如何解决Hive 类似匹配词边界

我是 Hive 正则表达式匹配的新手,正在努力寻找匹配单词边界的正确模式:

haystack RLIKE concat('(?i)\b','needle','\b')

不返回任何东西。

我在数据库中的样本值:

haystack
---------
needless to say
this is a needle
so many (needle)
these are needles

当我使用 haystack RLIKE concat('(?i)','needle') 时,它会返回所有行,但我实际上是在寻找 this is a needle

解决方法

在 Hive 中使用两个反斜杠:\\b

演示:

with mytable as (
select stack(4,'needless to say','this is a needle','so many (needle)','these are needles'
) as haystack
)

select haystack,haystack rlike concat('(?i)\\b','needle','\\b') from mytable;

结果:

haystack             _c1
needless to say      false
this is a needle     true
so many (needle)     true
these are needles    false

注意 so many (needle) 也匹配,因为 () 不是单词字符。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。