title: Padding with zeros in the middle of a string?
body: <p>Padding a number with leading zeros has been answered <a href="https://stackoverflow.com/questions/134934/display-number-with-leading-zeros">here</a>. But in my case I have a string character followed by digits. I want to add leading zeros after the string character, but before the digits, keeping the total length to 4. For example:</p>
  
  <pre><code>A1 -&gt; A001
  A12 -&gt; A012
  A123 -&gt; A123
  </code></pre>
  
  <p>I have the following code that gets me what I want, but is there a shorter way to do this without using re to split my string into text and numbers first? </p>
  
  <pre><code>import re
  mystr = 'A4'
  elements = re.match(r"([a-z]+)([0-9]+)", mystr, re.I)
  first, second = elements.groups()
  print(first + '{:0&gt;3}'.format(second))
  
  output = A004
  </code></pre>