title: Parsing time via regex for voice activated alarm
body: <p>I'm trying to write a regex expression that can properly parse as many of these possible verbal commands to set an alarm e.g.:</p>
  
  <p>Group 1:</p>
  
  <blockquote>
    <p>set an alarm at 3:50 p.m.<br>
      set an alarm for tomorrow at 3:50<br>
      set an alarm for 6 a.m.<br>
      set an alarm for 3 o'clock  </p>
  </blockquote>
  
  <p>Group 2:</p>
  
  <blockquote>
    <p>set an alarm in 1 hour 10 minutes<br>
      set an alarm in 59 minutes<br>
      set an alarm in 6 hours  </p>
  </blockquote>
  
  <p>Group 3:  </p>
  
  <blockquote>
    <p>set an alarm in 3 quarter hours from now<br>
      set an alarm in 2 and a half hours<br>
      set an alarm in half an hour  </p>
  </blockquote>
  
  <p>This expression works for Group 1:  </p>
  
  <pre><code>(\D)+(\d+)(?::)?(\d+)?(?: )?(a\.m\.|p\.m\.)?(.+)
  </code></pre>
  
  <p><a href="https://regex101.com/r/H6z5NU/3" rel="nofollow noreferrer">https://regex101.com/r/H6z5NU/3</a></p>
  
  <p>set an alarm for tomorrow at 3 p.m.<br>
    Group 1.  28-29   <code></code><br>
    Group 2.  29-30   <code>3</code><br>
    Group 5.  31-35   <code>p.m.</code>  </p>
  
  <p>set an alarm for tomorrow at 3:50 p.m.<br>
    Group 1.  28-29   <code></code><br>
    Group 2.  29-30   <code>3</code><br>
    Group 3.  31-33   <code>50</code><br>
    Group 5.  34-38   <code>p.m.</code>  </p>
  
  <p>The expression works for Group 2:</p>
  
  <pre><code>(\D)+(\d+){1,2}( hour| minute)((\D)+(\d+){1,2}( minute))?(.+)?
  </code></pre>
  
  <p><a href="https://regex101.com/r/3yt7tK/1" rel="nofollow noreferrer">https://regex101.com/r/3yt7tK/1</a>  </p>
  
  <p>set an alarm in 20 hours and 1 minute<br>
    Group 1.  15-16   <code></code><br>
    Group 2.  16-18   <code>20</code><br>
    Group 3.  18-23   <code>hour</code><br>
    Group 4.  23-37   <code>s and 1 minute</code><br>
    Group 5.  28-29   <code></code><br>
    Group 6.  29-30   <code>1</code><br>
    Group 7.  30-37   <code>minute</code>  </p>
  
  <p>set an alarm in 1 minute<br>
    Group 1.  15-16   <code></code><br>
    Group 2.  16-17   <code>1</code><br>
    Group 3.  17-24   <code>minute</code>  </p>
  
  <p>But I'm driving myself nuts trying to get the secret sauce that can handle combining the am/pm hour/minute.  </p>
  
  <p>Addendum:  I've got my own recognition parser built using various tools (e.g. vanilla python - no ML imports) and it already successfully handles several tasks... just trying to add an alarm setting task and hoping to get some regex help.  Thanks!</p>
  
  <p><strong>===========  Yet another update  ===========</strong>  </p>
  
  <p>This expression works for Group 1:  </p>
  
  <pre><code>(\D+)(noon|midnight|\d{1,2})(?::(\d{0,2})| o'clock)?(?: )?(p.m.|a.m.|noon|midnight)?
  </code></pre>
  
  <p><a href="https://regex101.com/r/H6z5NU/5" rel="nofollow noreferrer">https://regex101.com/r/H6z5NU/5</a></p>
  
  <p>And also handles "12 noon" or "midnight"</p>
  
  <p>And... this expression works well for both Group 2 and Group 3:</p>
  
  <pre><code>(\D)?(\d){0,2}(?: )?(and a )?(hour|minute|quarter|half)((\D)+(\d+){0,2}(?: )?(minute|hour))?(.+)?
  </code></pre>
  
  <p><a href="https://regex101.com/r/3yt7tK/2" rel="nofollow noreferrer">https://regex101.com/r/3yt7tK/2</a></p>
  
  <p>For now, I'll probably just use these two separately and determine the appropriate one by looking for the distinct keywords.</p>