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.ArrayList;
  7. import java.util.List;
  8. import java.util.regex.Matcher;
  9. import java.util.regex.Pattern;
  10.  
  11. /* Name of the class has to be "Main" only if the class is public. */
  12. class Ideone
  13. {
  14. public static void main (String[] args) throws java.lang.Exception
  15. {
  16. String s = "#Jay125,150012 90,#Jay222,150043 00,";
  17. Pattern pattern = Pattern.compile("#(Jay\\d+),(\\d+) (\\d+)");
  18. Matcher matcher = pattern.matcher(s);
  19.  
  20. List<String> listJay = new ArrayList<>();
  21. List<String> listFirstSubNum = new ArrayList<>();
  22. List<String> listSecSubNum = new ArrayList<>();
  23.  
  24. while (matcher.find()) {
  25. listJay.add(matcher.group(1));
  26. listFirstSubNum.add(matcher.group(2));
  27. listSecSubNum.add(matcher.group(3));
  28. }
  29.  
  30. System.out.println(listJay);
  31. System.out.println(listFirstSubNum);
  32. System.out.println(listSecSubNum);
  33. }
  34. }
Success #stdin #stdout 0.1s 48268KB
stdin
Standard input is empty
stdout
[Jay125, Jay222]
[150012, 150043]
[90, 00]