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>I think the regex you're looking for is:</p>

<pre><code>1+(?!\0)
</code></pre>

<p>i.e. match one or more 1s which aren't followed by a 0.</p>

<p>The one you have is specifically looking for ones that are followed by 0s.</p>

<p>you can play around with regexs on various jsfiddle like sites, with interactive explanations of what they're doing. ex:</p>

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

python regex