fork(2) 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 = "fghhhhjkjkljhdd";
  11. String regex = "(\\w)(\\1+)";
  12. Pattern r = Pattern.compile(regex);
  13. Matcher m = r.matcher(text);
  14. while (m.find()) {
  15. m.appendReplacement(sb, m.group(1) + (m.group(2).length()+1));
  16. }
  17. m.appendTail(sb); // append the rest of the contents
  18. System.out.println(sb);
  19. }
  20. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
fgh4jkjkljhd2