Regex python findall issue
<p>From the test string:</p>

<pre><code> test=text-AB123-12a
 test=text-AB123a
</code></pre>

<p>I have to extract only <code>'AB123-12'</code> and <code>'AB123'</code>, but:</p>

<pre><code> re.findall("[A-Z]{0,9}\d{0,5}(?:-\d{0,2}a)?", test)
</code></pre>

<p>returns:</p>

<pre><code>['', '', '', '', '', '', '', 'AB123-12a', '']
</code></pre>

<p>What are all these extra empty spaces? How do I remove them?</p>

<p>RegEx tester: <a href="http://www.regexpal.com/" rel="nofollow">http://www.regexpal.com/</a> says that your pattern string <code>[A-Z]{0,9}\d{0,5}(?:-\d{0,2}a)?</code> can match 0 characters, and therefore matches infinitely. </p>

<p>Check your expression one more time. Python gives you undefined result.</p>

python regex