title: Python regex to match character a number of times
body: <p>I am trying to create a regex to match a character a specified number of times in a string. The character does not have to occur right after it's last occurrence, so the regex has to match the character any where it occurs for the number of times it does while that number does not exceed the one given.</p>
  
  <p>Also this regex has to be <strong>overlapping</strong> this means that it has to find all substrings containing the specified character the amount of times it was specified; and it has to do this as many times as possible within the string.</p>
  
  <p>Here is my attempt, this one just brute-forces it's way and finds almost every possible string that contains that character:</p>
  
  <pre><code>import re
  c = raw_input()
  a = re.compile(r'(?=(.*{0}.*?))(?=(.*{1}.*))(?=(.*?{2}.*))'.format(c, c, c))
  print [ s for s in a.findall(raw_input()) ]
  </code></pre>
  
  <p>This works in that it tries to find all of them, but it sometimes does not find everything:</p>
  
  <pre><code>python
  Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) 
  [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
  Type "help", "copyright", "credits" or "license" for more information.
  &gt;&gt;&gt; import string_regex
  1
  10101
  [('10101', '10101', '10101'), ('0101', '0101', '0101'), ('101', '101', '101'), ('01', '01', '01'), ('1', '1', '1')]
  </code></pre>
  
  <p>It does not find the string '10' which it is supposed to find 2 times
  I need help to make the regex match just what I want not everything</p>