Hive 类匹配词边界

Hive rlike matching word boundary

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

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

return什么都没有。

我在数据库中的示例值:

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

当我使用 haystack RLIKE concat('(?i)', 'needle') 时,它 return 显示了所有行,但我实际上是在寻找 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)也是匹配的,因为()不是单词字符