Regex find ALL patterns betwen string
<p>I want to match digits betwen "000" or betwen \b and "000" or "000" and \b from a string like this: </p>

<pre><code>11101110001011101000000011101010111
</code></pre>

<p>I have tried with expressions like this:</p>

<pre><code>(?&lt;=000)\d+(?=000)
</code></pre>

<p>but I only get the largest occurrence </p>

<p>I expect to get:</p>

<pre><code>1110111
1011101
0
11101010111
</code></pre>

<p>You can use the <a href="https://pypi.python.org/pypi/regex" rel="nofollow"><code>regex</code> package</a> and the <code>.findall()</code> method:</p>

<pre><code>In [1]: s = "11101110001011101000000011101010111"

In [2]: import regex

In [3]: regex.findall(r"(?&lt;=000|^)\d+?(?=000|$)", s)
Out[3]: ['1110111', '1011101', '0', '00011101010111']
</code></pre>

<p>The <code>000|^</code> and <code>000|$</code> would help to match either the <code>000</code> or the beginning and the end of a string respectively. Also note the <code>?</code> after the <code>\d+</code> - we are making it <a href="http://stackoverflow.com/questions/2301285/what-do-lazy-and-greedy-mean-in-the-context-of-regular-expressions"><em>non-greedy</em></a>.</p>

<p>Note that the regular <code>re.findall()</code> would fail with the following error in this case:</p>

<blockquote>
  <p>error: look-behind requires fixed-width pattern</p>
</blockquote>

<p>This is because <code>re</code> does not support <em>variable-length lookarounds</em> but <code>regex</code> does.</p>

python regex string digits