fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.regex.Matcher;
  7. import java.util.regex.Pattern;
  8.  
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. String regex = "\\s*(.{30}[^.]*\\.|.+$)";
  14. String string = "The boy ate the apple. The sun is shining high in the sky. The answer to life the universe and everything is forty two, said the big computer.\n\n\n"
  15. + "The boy ate the apple. The sun is shining high in the sky. The answer to life the universe and everything is forty two, said the big computer. This is a test and this is a test\n\n"
  16. + "and this is a test.\n\n"
  17. + "This is \n\n"
  18. + "a test and then this is \n"
  19. + "a test again. Test";
  20.  
  21. Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
  22. Matcher matcher = pattern.matcher(string);
  23.  
  24. while (matcher.find()) {
  25. for (int i = 1; i <= matcher.groupCount(); i++) {
  26. System.out.println("Group " + i + ": " + matcher.group(i));
  27. }
  28. }
  29. }
  30. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
Group 1: The boy ate the apple. The sun is shining high in the sky.
Group 1: The answer to life the universe and everything is forty two, said the big computer.
Group 1: The boy ate the apple. The sun is shining high in the sky.
Group 1: The answer to life the universe and everything is forty two, said the big computer.
Group 1: This is a test and this is a test

and this is a test.
Group 1: This is 

a test and then this is 
a test again.
Group 1: Test