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>

<pre><code>r'\S*\d$' 
</code></pre>

<p>Will match all non-whitespace characters that end in a digit</p>

<p>Will match <code>AED=20180823</code></p>

<pre><code>r'\S*[a-zA-Z]$'
</code></pre>

<p>Matches all non-whitespace characters that end in a letter.</p>

<p>will match <code>AED=AED=FRI</code>
<code>AFN=FRI:SAT</code>
<code>AMD=SUN:SAT</code></p>

<p>Neither will  match </p>

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

<p>This will match both </p>

<pre><code>r'(\S*[a-zA-Z]$|\S*\d$)'
</code></pre>

<p>Replacing the * with the number of occurences you expect will be safer, the <code>(a|b)</code> is match a or match b</p>

python regex