fork(16) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.io.*;
  4.  
  5. import java.util.regex.Matcher;
  6. import java.util.regex.Pattern;
  7.  
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. String input = "The big black dog big black dog is a friendly friendly dog who lives nearby nearby.";
  15.  
  16. Pattern dupPattern = Pattern.compile("([ \\w]+)\\1", Pattern.CASE_INSENSITIVE);
  17. Matcher matcher = dupPattern.matcher(input);
  18.  
  19. while (matcher.find()) {
  20. input = input.replaceAll("([ \\w]+)\\1", "$1");
  21. }
  22. System.out.println(input);
  23.  
  24. }
  25. }
Success #stdin #stdout 0.12s 320512KB
stdin
Standard input is empty
stdout
The big black dog is a friendly dog who lives nearby.