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.*;
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String value1 = "A42z19z037z21zB942z21z4842zC33z449z3884z68z20z";
  13. String pattern1 = "([A-Z]|(?!\\A)\\G)(\\d+z)";
  14. Pattern ptrn = Pattern.compile(pattern1);
  15. Matcher matcher = ptrn.matcher(value1);
  16. ArrayList<ArrayList<String>> result_lst = new ArrayList<ArrayList<String>>();
  17. ArrayList<String> lst = null;
  18. while (matcher.find()) {
  19. if (!matcher.group(1).equals("")) {
  20. if (lst != null) result_lst.add(lst);
  21. lst = new ArrayList<String>();
  22. lst.add(matcher.group(1));
  23. }
  24. else {
  25. lst.add(matcher.group(2));
  26. }
  27. }
  28. if (lst != null) result_lst.add(lst);
  29. System.out.println(result_lst);
  30. }
  31. }
Success #stdin #stdout 0.12s 320576KB
stdin
Standard input is empty
stdout
[[A, 19z, 037z, 21z], [B, 21z, 4842z], [C, 449z, 3884z, 68z, 20z]]