If there are more than 2 characters "Hiiiiiii My frieeend!!!!!!!"
I need to be reduced to "Hii My frieend!!"
Please undestand that in my language there are many words with double chars. Thnx in advance
kplla
If there are more than 2 characters "Hiiiiiii My frieeend!!!!!!!"
I need to be reduced to "Hii My frieend!!"
Please undestand that in my language there are many words with double chars. Thnx in advance
kplla
Perl / regex (and if it's not english, Perl has given me better luck with Unicode than PHP):
#!/usr/bin/perl
$str = "Hiiiiii My Frieeeeend!!!!!!!";
$str =~ s/(.)\1\1+/$1$1/g;
print $str;
Here's another regex solution that uses lookahead (just for fun), in Java:
System.out.println(
"Hiiiiii My Frieeeeend!!!!!!!".replaceAll("(.)(?=\\1\\1)", "")
); // prints "Hii My Frieend!!"