如何查找是否有连续两次重复的单词 [英] How to find if there are words repeated twice in a row

查看:257
本文介绍了如何查找是否有连续两次重复的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我在MySQL数据库表字段中具有以下段落

For example i have the below paragraph in a MySQL database table field

当地球介于月球之间时,切断天文物体的照明,就像月食一样"

"The cutting off of the illumination of an astronomical object object, as in an eclipse of the Moon, when the Earth comes between"

此处"对象"一词连续出现两次(彼此相邻).

Here the word "object" appears twice in a row (next to each other).

我想检查这种情况是否出现在同一表的其他记录中.有没有一种简便的方法可以使用PHP和MySQL

I want to check if this case appears in other records in same table. Is there an easy way to do this using PHP and MySQL

推荐答案

此正则表达式有效:(\b\w+\b)(?=\s?\1)(请参阅

This regex works: (\b\w+\b)(?=\s?\1) (see example)

要使其在MySQL中工作,必须将Word Boundaries(\b)替换为MySQL等效的[[:<:]][[:>:]],并将\w替换为[[:alnum:]]:

To make it work in MySQL, the Word Boundaries (\b) must be replaced with MySQL equivalent [[:<:]] and [[:>:]], and \w with [[:alnum:]]:

SELECT * FROM your_table
WHERE your_field REGEXP '([[:<:]][[:alnum:]]+[[:>:]])(?=\\s?\\1)';

但是此查询给出了一个错误,因为,正如马特所说,MySQL 不支持反向引用.因此,当前的MySQL REGEXP无法实现.

But this query gives an error because, as Matt said, MySQL does not support backreferences. So, it's not possible with the current MySQL REGEXP.

这篇关于如何查找是否有连续两次重复的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆