Skip to main content
Regexflux

12-Hour Time with AM/PM

beginner

Matches time in 12-hour format with AM/PM indicator.

time12hourampmformat

Pattern

/(?:1[0-2]|0?[1-9]):[0-5]\d\s?[AaPp][Mm]/g

Try It

0 of 7 strings matched

Explanation

Matches hours 1-12 (with optional leading zero), minutes 00-59, optional space, and AM/PM indicator (case-insensitive).

Test Strings

Matching

  • 9:30 AM
  • 12:00PM
  • 01:45 pm
  • 11:59 AM

Non-matching

  • noon
  • 99:99
  • midnight

Language Compatibility

LanguageSupport
JSFull support
PYTHONFull support
JAVAFull support
PHPFull support
GOFull support

Code Snippets

const regex = /(?:1[0-2]|0?[1-9]):[0-5]\d\s?[AaPp][Mm]/g;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);

Related Patterns