title: How to create a time matching Regex pattern
body: <p>I have been writing a java program. In the program i am taking an input from the user which is a time. I take the input as a string and check if it matches a pattern. The pattern i want is of format : 10:15 AM</p>
  
  <p>This is what i tried but it doesn't seem to work.</p>
  
  <pre><code>public static boolean checkTimePattern(String time) {
      Pattern pattern = Pattern.compile("\\d{1}:\\d{1}^[A]{1}[M]{1}");
     if(pattern.matcher(time).matches()){
         return true;
     }else{
         return false;
     }
  }
  </code></pre>
  
  <p>Thank you.</p>