K
Kannan S
How do I replace consecutive occurances of any character in a string,
to just one. eg: "aaabbbcc" to "abc"
Pattern repeatedChars = Pattern.compile("([a-z]){2,}+");
String s1 = repeatedChars.matcher("aaabbbcc").replaceAll("\\1");
The regex part seems to be correct, but all consecutive occurances are
replaced by a single "." and s1 is now "...".
Any comments?
Thanks
--kannan
to just one. eg: "aaabbbcc" to "abc"
Pattern repeatedChars = Pattern.compile("([a-z]){2,}+");
String s1 = repeatedChars.matcher("aaabbbcc").replaceAll("\\1");
The regex part seems to be correct, but all consecutive occurances are
replaced by a single "." and s1 is now "...".
Any comments?
Thanks
--kannan