Suppose I have a string like :
String s = "hellllooooo howwwwwww areeeeeee youuuuuuu";
I want to discard the repeated letters and want to get :
"helloo howw aree youu"
I have done the matching using ::
matches(".*([a-z])\\1{3,}.*"
But how can I replace the helloooooooo to helloo and the others ?
Any of the following produces the result you want:
s = s.replaceAll("([a-z])\\1+", "$1$1");
s = s.replaceAll("(([a-z])\\2)\\2*", "$1");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With