PHP - remove duplicate syllable word

I am new and want to know how to use regex in php. if I have text like "haha" "abcabcabc" "hehehe" "cupcupcupcup" (contain a duplicate of the syllable word).

How to delete this text?

(say $text="cupcupcup"; ", how to do it like $text=""; )

Sorry if I have the same request (I have a search but cannot find a page describing my problem)

Thank you for your understanding.:)

+4
source share
4 answers

Try

 $txt = preg_replace("/^(.*)(\\1+)$/", "", $txt); 

This searches for a sequence at the beginning of the line, then matches at least one repetition of that line, and then matches the end of the line.

eg.

 $txt = preg_replace("/^(.*)(\\1+)$/", "", "cupcupcup"); //=> "" $txt = preg_replace("/^(.*)(\\1+)$/", "", "cucupcup"); //=> "cucupcup" 
+4
source

Well, I think it would do

 \b(?=\w*[aeiou]\w*)(\w*)\1+ ------------- | |->check if its a syllable word 

replace it with ""

+2
source

So here is what I came up with:

 ([b-df-hj-np-tv-xz][aeiouy](?:[az])?|[aeiouy][b-df-hj-np-tv-xz](?:[az])?)(\1){2,} 

Demo version

Explanation:

  • [b-df-hj-np-tv-xz] : match consonants.
  • [aeiouy] : match vowels.
  • [az] : match the letter.
  • ([b-df-hj-np-tv-xz][aeiouy](?:[az])? Match the consonant, followed by a vowel and possibly followed by a letter.
  • |[aeiouy][b-df-hj-np-tv-xz](?:[az])?) : or coincidence with a vowel, followed by a consonant, followed by, possibly, a letter.
  • (\1){2,} : Repeat group 1 two or more times.
0
source

if the text:

 $txt = preg_replace("/(.*)(\\1+)/", "", "the text is cupcupcup and cupcupcupa"); 

which will remove cupcupcup and cupcupcupa . how to simply remove cupcupcup ?

0
source

Source: https://habr.com/ru/post/1484046/


All Articles