Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find if there are words repeated twice in a row

Tags:

php

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).

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

like image 477
daron Avatar asked Jun 22 '10 14:06

daron


People also ask

What is it called when a word is repeated twice in a row?

In rhetoric, epizeuxis is the repetition of a word or phrase in immediate succession, typically within the same sentence, for vehemence or emphasis.

What do you do when words appear twice in a row?

Simply recast the final phrase (“She gives in every time”) or flip the phrase to the front (“In every case, she gives in”).

Can you use that twice in a row?

Using 'That' Twice in a Row When you're trimming unnecessary uses of “that” from your writing, be sure to pay attention to sentences where it appears multiple times or even twice in a row (“that that”). These sentences can be grammatically correct but stylistically undesirable.

Why do I keep typing the same word twice?

Palilalia (from the Greek πάλιν (pálin) meaning "again" and λαλιά (laliá) meaning "speech" or "to talk"), a complex tic, is a language disorder characterized by the involuntary repetition of syllables, words, or phrases.


2 Answers

if (preg_match('/\\b(\\w+)\\s\\1\\b/', $subject)) {
    //has repetition
}
like image 117
Artefacto Avatar answered Nov 15 '22 04:11

Artefacto


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

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)';

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.

like image 35
True Soft Avatar answered Nov 15 '22 06:11

True Soft