Regex ('foo'|'bar') notation
<p>I'm using regex to parse some time data, but my attempt is not matching as I would expect.  Here's my code:</p>

<pre><code>import re
print re.findall("\d+:\d+ (am|pm)", "11:30 am - 2:20 pm")
</code></pre>

<p>This produces <code>['am', 'pm']</code>, not <code>['11:30 am', '2:20 pm']</code>, which is what I want.</p>

<p>I can produce the result that I want with <code>\d+:\d+ am|\d+:\d+ pm</code>, but that is a little blunt and I want to know why the other is not working?</p>

<p>You probably don't even need regular expressions to split this particular string. If applicable, you can use the regular <a href="https://docs.python.org/2/library/stdtypes.html#str.split" rel="nofollow"><code>str.split()</code></a>:</p>

<pre><code>&gt;&gt;&gt; s = "11:30 am - 2:20 pm"
&gt;&gt;&gt; s.split(" - ")
['11:30 am', '2:20 pm']
</code></pre>

<p>This, of course, does not enforce items to be "time"-like strings.</p>

python regex