title: VBA Regular Expression to match a time range like "1:30pm - 12:00am"
body: <p>I am trying to use a VBA regular expression to validate a time range of the form: <code>#0:00xm - #0:00xm</code> where <code>x</code> is <code>a</code> or <code>p</code>.  So the string literal could be <code>"1:30pm - 12:00am"</code>.  I want to match cells that have this pattern.</p>
  
  <p>When I use the regular express in this online tool: <code>http://public.kvalley.com/regex/regex.asp</code> and check my expression, it matches correctly.</p>
  
  <p>However, when I use the same expression in VBA, it does not match.</p>
  
  <pre><code>Dim rRange As Range
  Dim rCell As Range
  
  Set rRange = Range("A2", "A4") '"G225")
  
  For Each rCell In rRange.Cells
  MsgBox (rCell.Value)
      If rCell.Value Like "^([0-9]{1,2}[:][0-9]{2}[apm]{2}[ ][-][ ][0-9]{1,2}[:][0-9]{2}[apm]{2})$" Then
      MsgBox ("YES")
          'rCell.Interior.Color = RGB(0, 250, 0)
      Else
      MsgBox ("NO")
          'rCell.Interior.Color = RGB(250, 0, 0)
      End If
  Next rCell
  </code></pre>