Extracting certain date and time using regex
<p>Regex expression tested using <a href="http://pythex.org/" rel="nofollow">http://pythex.org/</a> </p>

<blockquote>
  <p>Expression:
  (\d{2})/.-/.-\s([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$</p>
</blockquote>

<p>I only want to be able to print out 30/06/2016 17:15 as two individual variable.
The above cant work! can anybody enlighten me on my expression? It seems to be matching "30/06/2016 17:15" exactly only </p>

<p>It works fine using a combination of <code>ast.literal_eval</code> and <code>re</code>:</p>

<p><code>ast.literal_eval</code> gets rid of the <code>tuple</code>-like structure for you. The rest is a piece of cake.</p>

<p>This solution is more robust than regex-only solutions:</p>

<pre><code>import ast,re

a = "('=====================================', '30/06/2016 17:15 T001 201603301', 'ORDER: C002946', 'Cashier: 001', '--------------------------------------')"

t=ast.literal_eval(a)

z=re.compile(r"(\d\d/\d\d/\d\d\d\d)\s(\d\d:\d\d)")

m = z.match(t[1])

if m:
    print("date: {}, time {}".format(m.group(1),m.group(2)))
</code></pre>

<p>Result:</p>

<pre><code>date: 30/06/2016, time 17:15
</code></pre>

<p>Remarks:</p>

<ul>
<li>The regex is not optimal, but that's not the hardest part once the tuple is read and parsed.</li>
<li>Maybe it would be even better to get a real <code>time</code> structure using <code>time.strptime</code> (no need for regex in that case).</li>
</ul>

python regex