MySQL手册没有非常详细地说明它支持什么表达式,因此我不确定MySQL是否完全可以实现以下操作.
我正在尝试使用RLIKE创建与以下内容匹配的查询.
任务是从SQL中获取所有句子,这些句子至少包含给定句子中的任何两个单词.
假设我在正则表达式中使用了一些特定的词:
hello, dog
我在数据库中有以下句子:
hello from dog
hello hello cat
dog says hello
dog dog goes away
big bad dog
从那些我只想匹配的东西中
hello from dog
dog says hello
现在我有这样的事情:
SELECT *
FROM test
WHERE
test RLIKE '(hello|dog).*(hello|dog)'
问题是-我也得到了那些不需要的东西
hello hello cat
dog dog goes away
因此,我想我需要在第二个(hello | dog)之前进行反向引用.
用伪代码看起来像这样:
RLIKE '(hello OR dog) anything can be here (hello OR dog, but not the word which already was in the previous group)'
所以可能像:
'(hello|dog).*(negative backreference to the 1st group goes here)(hello|dog)'
这样的否定反向引用可以在MySQL正则表达式中完成吗?
或者,也许有更好的方式编写正则表达式,它做同样的事情,但同时考虑到查询将由某些C代码生成,因此生成起来应该不会太复杂?