Python regex issue. Validation works but in two parts, I to extract each valid 'part' separately
<p>My code is:</p>

<pre><code>test1 = flight
###Referencelink: http://academe.co.uk/2014/01/validating-flight-codes/
#Do not mess up trailing strings
p = re.compile(r'^([a-z][a-z]|[a-z][0-9]|[0-9][a-z])[a-z]?[0-9]{1,4}[a-z]?$')
m = p.search(test1)  # p.match() to find from start of string only
if m:
 print '[200],[good date and time]'  # group(1...n) for capture groups
else:
 print('[error],[bad flight number]'),quit()
</code></pre>

<p>I need to get the carrier code (the first bit) and the flight number(second bit) separately. </p>

<p>Can I extract the regex as in: a = 'first valid part' of regex, b = 'second valid part'</p>

<p>Try this maybe.</p>

<pre><code>p = re.compile(r'^([a-z][a-z]|[a-z][0-9]|[0-9][a-z])([a-z]?[0-9]{1,4}[a-z]?)$')
m = p.findall(test1)
</code></pre>

python regex api extract