fork 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. /* 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 line = "TABLE1\n=======\n1 | 2\n15 | 2\n3 | 15\n\nTABLE2\n=======\n3 | 5\n12 | 2\n17 | 7";
  15. String pattern = "(?s)(?:(TABLE\\d+)|\\G)(?:(?!TABLE).)+?(\\d+)\\s+\\|\\s+(\\d+)";
  16. Pattern r = Pattern.compile(pattern);
  17. Matcher m = r.matcher(line);
  18. int flag = 0;
  19.  
  20. while (m.find()) {
  21. if (m.group(1) != null) {
  22. flag = 0;
  23. }
  24.  
  25. if (flag == 0) {
  26. System.out.println(m.group(1) + "\n" + m.group(2) + "\n" + m.group(3));
  27. flag = 1;
  28. } else {
  29. System.out.println(m.group(2) + "\n" + m.group(3));
  30. }
  31. }
  32. }
  33. }
Success #stdin #stdout 0.09s 320576KB
stdin
Standard input is empty
stdout
TABLE1
1
2
15
2
3
15
TABLE2
3
5
12
2
17
7