title: How do I repeat a parenthesized group n times using a Python regular expression?
body: <p>I'm trying to get pairs of <code>|&lt;digit&gt;&lt;whitespace&gt;</code> out of a string with many of them. I'm using the regex <code>(\|\d+\s+){2}</code> to do this, i.e.:</p>
  
  <pre><code>&gt;&gt;&gt; import re
  &gt;&gt;&gt; s = '|11 |22    |\n|33  |444 |\n'
  &gt;&gt;&gt; re.findall('(\|\d+\s+){2}', s)
  ['|22    ', '|444 ']
  </code></pre>
  
  <p>I expected instead is:</p>
  
  <pre><code>['|11 |22    |', '|33  |444 |']
  </code></pre>
  
  <p>because () should define a group and {2} should repeat it twice. Why doesn't it do that, and what's a better way of doing it?</p>