fork(10) 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 str = "hello hello world world world world";
  11. String pat = "\\b(\\w+)(?:\\s+\\1\\b)+";
  12. String res = str.replaceAll(pat, "$1");
  13. System.out.println(res);
  14. }
  15. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
hello world