fork(1) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.*;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String s = "fffooooobbbbaarrr";
  11. int threshold = 2; // Should not be less than 1
  12. String pattern = String.format("((\\w)\\2{%1$s})\\2*", threshold-1);
  13. System.out.println(pattern);
  14. System.out.println(s.replaceAll(pattern, "$1"));
  15. }
  16. }
Success #stdin #stdout 0.1s 28068KB
stdin
Standard input is empty
stdout
((\w)\2{1})\2*
ffoobbaarr