Regular Expression with letter
<p>I need to match things that format something along the lines of 
657432-76,   54678-01,   54364<strong>A</strong>-12</p>

<p>I got <code>(r'^\d{6}-\d{2}$')</code>
and   <code>(r'^\d{5}-\d{2}$')</code>
but how do you get the letter?</p>

<p>thanks!!</p>

<p>How about this expression:</p>

<pre><code>&gt;&gt;&gt; re.search(r'^\d+[A-Z]?-\d+$','657432A-76')
&lt;_sre.SRE_Match object; span=(0, 10), match='657432A-76'&gt;
&gt;&gt;&gt; 
&gt;&gt;&gt; re.search(r'^\d+[A-Z]?-\d+$','657432-76')
&lt;_sre.SRE_Match object; span=(0, 9), match='657432-76'&gt;
&gt;&gt;&gt; 
&gt;&gt;&gt; re.search(r'^\d+[A-Z]?-\d+$','65743-76')
&lt;_sre.SRE_Match object; span=(0, 8), match='65743-76'&gt;
&gt;&gt;&gt; 
</code></pre>

<p>Or if the format is as : <br /></p>

<p><code>[At most six digits][Possibility of a letter][-][At most two digits]</code> <br /> </p>

<p>Then:</p>

<pre><code>&gt;&gt;&gt; re.search(r'^\d{,6}[A-Z]?-\d{,2}$','65743A-76')
&lt;_sre.SRE_Match object; span=(0, 9), match='65743A-76'&gt;
&gt;&gt;&gt; 
&gt;&gt;&gt; re.search(r'^\d{,6}[A-Z]?-\d{,2}$','657436-76')
&lt;_sre.SRE_Match object; span=(0, 9), match='657436-76'&gt;
</code></pre>

python regex format expression