fork download
  1. import java.util.*;
  2. import java.util.regex.*;
  3. import java.lang.*;
  4. import java.io.*;
  5.  
  6. class Ideone {
  7. public static void main (String[] args) throws java.lang.Exception {
  8. String input = "w ww www wwww wwwww wwwwwww wwwwww aaa bbb zzzzzz cccc";
  9. Pattern pattern = Pattern.compile("\\b\\w{3,5}\\b");
  10. Matcher matcher = pattern.matcher(input);
  11. int count = 0;
  12. while (matcher.find()) {
  13. count++;
  14. }
  15. count -= count % 2;
  16. String result = String.join("", (CharSequence[]) pattern.split(input, count + 1));
  17. System.out.println(result);
  18. }
  19. }
Success #stdin #stdout 0.11s 320512KB
stdin
Standard input is empty
stdout
w ww    wwwwwww wwwwww   zzzzzz