Searching to End of String in Regex
<p>I am trying to extract all sequences of '1's from a string of binary digits (0 and 1) and get them into a <code>list</code>. <br/>For example the string may be of the form <code>001111000110000111111</code>. And I am looking for a list that looks like this <code>["1111", "11", "111111"]</code>. </p>

<p>I am using the python <code>findall</code> function with the following <code>([1]+?)0</code>. However, it does not match the last sequence of 1's since that ends with a <code>EOS</code> rather than a '0'. I have tried to use <code>([1]+?)0|$</code> to try to capture the <code>EOS</code> as a valid delimited. </p>

<p>But that fails too.<br/> Any help appreciated. </p>

<p>What you are trying:</p>

<pre><code>([1]+?)0
</code></pre>

<p><img src="https://www.debuggex.com/i/bHmtnovezOT8omWZ.png" alt="Regular expression visualization"></p>

<p><a href="https://regex101.com/r/fJ7lN1/1" rel="nofollow">Regex101 Demo</a></p>

<pre><code>([1]+?)0|$
</code></pre>

<p><img src="https://www.debuggex.com/i/H9GddLB8b0Zz0ixI.png" alt="Regular expression visualization"></p>

<p><a href="https://regex101.com/r/fJ7lN1/2" rel="nofollow">Regex101 Demo</a></p>

<p>What will work:</p>

<pre><code>(1+)
</code></pre>

<p><img src="https://www.debuggex.com/i/DcO4jZifB64t-Zc6.png" alt="Regular expression visualization"></p>

<p><a href="https://regex101.com/r/fJ7lN1/3" rel="nofollow">Regex101 Demo</a></p>

python regex