If the solution is based PHPand regexexcellent, you can do:
$str = "Hiiiiiii My frieeend!!!!!!!";
$str = preg_replace('#(.)\1+#','$1',$str);
echo $str; // prints Hi My friend!
$str = preg_replace('#(.)\1{2,}#','$1$1',$str);
echo $str;
You can also use the ones regexused above in Perl:
$ str = "Hiiiiiii My frieeend !!!!!!!";
$ str = ~ s / (.) \ 1 {2,} / $ 1 $ 1 / g;