Python regex similar expressions
<p>I have a file with two different types of data I'd like to parse with a regex; however, the data is similar enough that I can't find the correct way to distinguish it.</p>

<p>Some lines in my file are of form:</p>

<pre><code>AED=FRI
AFN=FRI:SAT
AMD=SUN:SAT
</code></pre>

<p>Other lines are of form</p>

<pre><code>AED=20180823
AMD=20150914
AMD=20150921
</code></pre>

<p>The remaining lines are headers and I'd like to discard them.  For example</p>

<pre><code>[HEADER: BUSINESS DATE=20160831]
</code></pre>

<p>My solution attempt so far is to match first three capital letters and an equal sign, </p>

<pre><code>r'\b[A-Z]{3}=\b'
</code></pre>

<p>but after that I'm not sure how to distinguish between dates (eg 20180823) and days (eg FRI:SAT:SUN).</p>

<p>The results I'd expect from these parsing functions:</p>

<pre><code>Regex weekday_rx = new Regex(&lt;EXPRESSION FOR TYPES LIKE AED=FRI&gt;);
Regex date_rx = new Regex(&lt;EXPRESSION FOR TYPES LIKE AED=20160816&gt;);


weekdays = [weekday_rx.Match(line) for line in infile.read()]
dates = [date_rx.Match(line) for line in infile.read()]
</code></pre>

<p>The following is a solution in Python :)</p>

<pre><code>import re

p = re.compile(r'\b([A-Z]{3})=((\d)+|([A-Z])+)')

str_test_01 = "AMD=SUN:SAT"
m = p.search(str_test_01)
print (m.group(1))
print (m.group(2))


str_test_02 = "AMD=20150921"
m = p.search(str_test_02)
print (m.group(1))
print (m.group(2))

"""
&lt;Output&gt;
AMD
SUN
AMD
20150921
"""
</code></pre>

python regex