title: python regex - optional match
body: <p>I have bunch of strings that comes in this flavor:</p>
  
  <pre><code>#q1_a1
  #q7
  </code></pre>
  
  <p>basically # is the sign that has to be ignored.
  after #, there comes a single-letter alphabet plus some number.
  optionally, some alphabet + number combination can be followed after <code>_</code> (underbar).</p>
  
  <p>here's what I came up with:</p>
  
  <pre><code>&gt;&gt;&gt; pat = re.compile(r"#(.*)_?(.+)?")
  &gt;&gt;&gt; pat.match('#q1').groups()
  ('q1', None)
  </code></pre>
  
  <p>the problem is strings of <code>#q1_a1</code> format. when I apply what I made to such strings:</p>
  
  <pre><code>&gt;&gt;&gt; pat.findall('#q1_f1')
  [('q1_f1', '')]
  </code></pre>
  
  <p>any suggestions? </p>