fork download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. public class Main {
  5. public static void main(String[] args) {
  6. // Test
  7. String str = "XYZ SuperMarket 10.00AM - 10.00PM";
  8. System.out.println(getTimeSlot(str));
  9. }
  10.  
  11. static String getTimeSlot(String str) {
  12. Matcher matcher = Pattern
  13. .compile("\\d{1,2}(?:[.:]\\d{1,2})?\\s*(?i)[AP]M\\s*-\\s*\\d{1,2}(?:[.:]\\d{1,2})?\\s*[AP]M")
  14. .matcher(str);
  15. String timeSlot = "";
  16. if (matcher.find()) {
  17. timeSlot = matcher.group();
  18. }
  19. return timeSlot;
  20. }
  21. }
Success #stdin #stdout 0.08s 48496KB
stdin
Standard input is empty
stdout
10.00AM - 10.00PM