fork(66) download
  1. import java.util.*;
  2. import java.util.regex.*;
  3. import java.lang.*;
  4.  
  5. class Main
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. String time = "14:35:59.99";
  10. String timeRegex = "([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])(?:\\.([0-9]{1,3}))?";
  11. Pattern pattern = Pattern.compile(timeRegex);
  12. Matcher matcher = pattern.matcher(time);
  13. if(matcher.matches()) {
  14. String hours = matcher.group(1);
  15. String minutes = matcher.group(2);
  16. String seconds = matcher.group(3);
  17. String miliSeconds = matcher.group(4);
  18. System.out.println(hours + ", " + minutes + ", " + seconds + ", " + miliSeconds);
  19. }
  20. }
  21. }
Success #stdin #stdout 0.03s 245632KB
stdin
Standard input is empty
stdout
14, 35, 59, 99