fork(3) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.*;
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String text = "aaaaaaBccccCCCCd"; //a6B1c4C4d1
  11. String regex = "(.)(\\1*)";
  12. String pattern = "test";
  13. Pattern r = Pattern.compile(regex);
  14. Matcher m = r.matcher(text);
  15. while (m.find()) {
  16. m.appendReplacement(sb, m.group(1) + (m.group(2).length()+1));
  17. }
  18. m.appendTail(sb); // append the rest of the contents
  19. System.out.println(sb);
  20. }
  21. }
Success #stdin #stdout 0.05s 711168KB
stdin
Standard input is empty
stdout
a6B1c4C4d1