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><strong>Matching</strong>: To match one or more <code>1</code>s, use <code>1+</code> regex.</p>

<p><strong>Splitting</strong>: You may split with 1 or more <code>0</code>s and remove empty elements.</p>

<p>See <a href="http://ideone.com/sH8MX3" rel="nofollow">Python demo</a>:</p>

<pre><code>import re
s = '001111000110000111111'
print(re.findall('1+', s))                   # ['1111', '11', '111111']
print([x for x in re.split('0+', s) if x])   # ['1111', '11', '111111']
</code></pre>

python regex