0

Helo,

I've this RegEx to delete double letter on a string :

<?
$string = "Heeeeelloo";
echo preg_replace( '`(.*)\1`', '$1',$string)."\n";

The current result is : Heeelo

But i would like this result : Helo

What's wrong ? Thanks

NicoMinsk
  • 1,716
  • 6
  • 28
  • 53
  • 1
    You should _definitely_ look at [this question](http://stackoverflow.com/questions/8391958/sanitize-sentence-in-php) and answers. – Bojangles Apr 16 '12 at 16:58

1 Answers1

3

Just do:

preg_replace( '`(.)\1+`', '$1',$string);
Toto
  • 89,455
  • 62
  • 89
  • 125