title: Python regex matching only if digit
body: <p>Given the regex and the word below I want to match the part after the - (which can also be a _ or space) only if the part after the delimiter is a digit and nothing comes after it (I basically want to to be a number and number only). I am using group statements but it just doesn't seem to work right. It keeps matching the 3 at the beginning (or the 1 at the end if I modify it a bit). How do I achieve this (by using grouping) ?</p>
  
  <p>Target word: <code>BR0227-3G1</code></p>
  
  <p>Regex: <code>([A-Z]*\s?[0-9]*)[\s_-]*([1-9][1-9]*)</code></p>
  
  <p>It should not match 3G1, G1 , 1G</p>
  
  <p>It should match only pure numbers like 3,10, 2 etc. </p>
  
  <p>Here is also a helper web site for evaluating the regex: <a href="http://www.pythonregex.com/" rel="nofollow">http://www.pythonregex.com/</a></p>
  
  <p>More examples:</p>
  
  <p>It should match:</p>
  
  <pre><code>BR0227-3
  BR0227 3
  BR0227_3
  </code></pre>
  
  <p>into groups <code>(BR0227) (3)</code></p>
  
  <p>It should only match <code>(BR0227)</code> for</p>
  
  <pre><code>BR0227-3G1
  BR0227-CS
  BR0227
  BR0227-
  </code></pre>