Regex doesn't filter out the right text on datatime
<p>I have a string below:</p>

<pre><code>senton = "Sent:                               Friday, June 18, 2010 12:57 PM"
</code></pre>

<p>I created a regex to filter out the datetime portion:</p>

<pre><code>reg_datetime = "(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}, \d{4} \d{2}:\d{2} (AM|PM)"
</code></pre>

<p>I tested the regex in regex101.com and it works as expected, however, when running it in my python test script, it fails to give me the right text, can anyone help me fix it?</p>

<p>Using it this way:</p>

<pre><code>real_senton = re.findall(reg_datetime, senton)
print real_senton
</code></pre>

<p>Produces this result (<a href="https://i.stack.imgur.com/Si8U8.jpg" rel="nofollow">here is the screenshot</a>):</p>

<pre><code>[('Friday', 'June', 'PM')]
</code></pre>

<p>Thank you very much.</p>

<p>The problem is that the match results that are returned to you are the ones between '(' ')' which are called group match.
Thus, your regex should look like this to return all the data:  </p>

<pre><code>reg_datetime = "(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (January|February|March|April|May|June|July|August|September|October|November|December) (\d{1,2}), (\d{4}) (\d{2}:\d{2}) (AM|PM)"
</code></pre>

<p>You can see <a href="https://regex101.com/r/caY6xP/1" rel="nofollow">here</a> the demo. Or if you want all the date in one single string, just add all the regex between '(' ')' </p>

python regex