fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. /* The class name doesn't have to be Main, as long as the class is not public. */
  4. class Main
  5. {
  6. public static final String EXAMPLE_TEST2 =
  7. "start{outer1}\n" +
  8. "Recipe A:\n" +
  9. "start{inner1}\n" +
  10. "-ingredient1\n" +
  11. "-ingredient2\n" +
  12. "end{inner1}\n" +
  13. "end{outer1}\n" +
  14. "... something ...\n" +
  15. "... blah blah blah ...\n" +
  16. "start{outer2}\n" +
  17. "Recipe B:\n" +
  18. "start{inner1}\n" +
  19. "- ingredient1\n" +
  20. "end{inner1}\n" +
  21. "end{outer2}\n" +
  22. "... something ...";
  23. public static void main (String[] args)
  24. {
  25. String[] splitString2 = EXAMPLE_TEST2.split("(?sm)start\\{(.*?)\\}((start\\{(.*?)\\}.*?end\\{(\\4)\\})|.)*?end\\{(\\1)\\}");
  26. for (String string : splitString2) {
  27. System.out.println(string);
  28. }
  29. }
  30. }
Success #stdin #stdout 0.07s 380160KB
stdin
1
2
10
42
11
stdout

... something ...
... blah blah blah ...


... something ...