fork(3) 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 line = "car water apple 04:48 05:18 05:46 06:16 06:46 07:16 07:46\nbridge night 04:57 05:27 05:56 06:26 06:56 07:26 07:56";
  13. List<String[]> allMatches = new ArrayList<String[]>();
  14. Matcher m = Pattern.compile("(?m)^(.*?)\\s*((?:\\d+:\\d+\\s*)*)$")
  15. .matcher(line);
  16. while (m.find()) {
  17. allMatches.add(new String[] { m.group(1), m.group(2)});
  18. }
  19.  
  20. for(String[] object: allMatches){
  21. System.out.println(Arrays.toString(object));
  22. }
  23. }
  24. }
Success #stdin #stdout 0.1s 320320KB
stdin
Standard input is empty
stdout
[car water apple, 04:48 05:18 05:46 06:16 06:46 07:16 07:46]
[bridge night, 04:57 05:27 05:56 06:26 06:56 07:26 07:56]