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>Your pattern is set to match zero length characters with the lower limits of your <em>character set</em> quantifier set to 0. Simply setting to 1 will produce the results you want:   </p>

<pre><code>&gt;&gt;&gt; import re
&gt;&gt;&gt; test = ''' test=text-AB123-12a
...  test=text-AB123a'''
&gt;&gt;&gt; re.findall("[A-Z]{1,9}\d{1,5}(?:-\d{0,2}a)?", test)
['AB123-12a', 'AB123']
</code></pre>

python regex