title: Python regex get with zero or more occurences within the pattern
body: <p>I've a working regex that's giving me the results that I want, yet it doesn't contain the safety it needs. (Fool-proof)</p>
  
  <p>Lets say I have a regex that matches parts of a path, something along the lines of:</p>
  
  <pre><code>import re
  path = "C:/Projects/foo/dev/model/props/furniture/couch/data/fbx"
  regex = re.compile("(.+)/dev/model/(.+)/(.+)/data/fbx")
  m = regex.search(path)
  if m:
      print m.groups()
  
  # ('C:/Projects/foo', 'props/furniture', 'couch')
  </code></pre>
  
  <p>I want to be able to replace the <em>match any character up till the following part of the regex</em> with something that will match one or more folders.</p>
  
  <p>Let's say we define a folder for simplicity as word characters (none or more) ending with a slash it would be:</p>
  
  <pre><code>[\w]*/
  </code></pre>
  
  <p>And I want to group zero to ten of those, how would I do that?</p>
  
  <p>In my mind I had something like (note that this doesn't work!):</p>
  
  <pre><code># match any number of word characters ending with a slash zero to ten times
  ([[\w]*/]{0,10})
  
  # match any number of word characters ending with a slash zero to one time
  ([[\w]*/]?)
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>Based on RedBaron and jamylak's answer I came up with the following:</p>
  
  <pre><code>((?:[:\w]+/){0,3})
  </code></pre>
  
  <p>This will group zero to three occurences [:\w] characters ending with a slash '/'. With the ?: at the beginning of the group it's not being send back to the matched groupings. So yet the outer group that combines them is. Therefore we only get the fully grouped result back.</p>
  
  <p>The only issue with this is that I want the last part to also possibly match a file. (So not ending with a slash.) I even prefer to get it back without the trailing slash from the regex, but I could also easily strip that of the end of the result.</p>
  
  <p>Any feedback is greatly appreciated. If this is the way to go I'll add it as an answer.</p>
  
  <p>EDIT:</p>
  
  <p>It's related to: <a href="https://stackoverflow.com/questions/15531977/finding-folders-back-based-on-a-predefined-folder-structure">Finding folders back based on a predefined folder structure</a></p>
  
  <p><strong>UPDATE/EDIT:</strong></p>
  
  <p>Based on all the answers given so far I've come up with a variety of tries, yet they all end up extremely slow in the end.</p>
  
  <pre><code>import re
  path = "C:/Projects/foo/dev/model/props/furniture/couch/data/fbx"
  regex = re.compile(r"""((?:^(?:[\w:]+/?)+)|(?:(?&lt;=/)(?:[\w]+/?)+))/dev/model/""")
  print 'search start'
  m = regex.search(path)
  print 'search done'
  if m:
      print 'match', m, m.groups()
  else:
      print 'no match'
  </code></pre>
  
  <p>I'm not entirely sure how to speed this up!</p>