title: Regex group match exactly n times
body: <p>I have to validate next string format:</p>
  
  <pre><code>text-text-id-text
  </code></pre>
  
  <p>Separator is character '-'. Third column must always be id. I wrote next regex (in python) which validates string:</p>
  
  <pre><code>import re
  
  s = 'col1-col2-col3-id' # any additional text at the end
                          # is allowed e.g. -col4-col5
  print re.match('^(.*-){3}id(-.*)?$', s) # ok 
  print re.match('^(.*-){1}id(-.*)?$', s) # still ok, is should not be
  </code></pre>
  
  <p>I tried adding non-greedy mode, but result is still the same: </p>
  
  <pre><code>^(.*?-){1}id(-.*)?$
  </code></pre>
  
  <p>What am I missing in my regex? I could just validate string like this:</p>
  
  <pre><code>&gt;&gt;&gt; import re
  &gt;&gt;&gt; print re.split('-', 'col1-col2-col3-id')
  ['col1', 'col2', 'col3', 'id']
  </code></pre>
  
  <p>And then check if the third element matches id, but I am interested in why does the first regex works as mentioned above.</p>