<div dir="ltr">Hi Joe,<div><br></div><div>I hereby accuse you of abusing regular expressions where less will do:</div><div><br></div><div><div>3> [P || P <- binary:split(<<"123abcabc456">>, <<"abc">>, [global]), P /= <<>>]. </div>

<div>[<<"123">>,<<"456">>]</div></div><div><br></div><div>In Standard ML, there are two token-split operations,</div><div><br></div><div><a href="http://www.standardml.org/Basis/string.html#SIG:STRING.tokens:VAL">http://www.standardml.org/Basis/string.html#SIG:STRING.tokens:VAL</a><br>

</div><div><br></div><div>the important notion being that the 'tokens' variant omits redundant whitespace (what you want) and 'fields' keeps the whitespace (what you want when parsing e.g., CSV files). The code in e(3) probably doesn't generate a lot of garbage.</div>

</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Feb 14, 2014 at 10:41 AM, Joe Armstrong <span dir="ltr"><<a href="mailto:erlang@gmail.com" target="_blank">erlang@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I'm sitting here feeling very stupid, can anybody explain to me in terms that<div>a child of five could understand what's going on here:</div>

<div><br></div><div>Problem: I want to split a string on repeated  occurrences of the string</div>
<div>"abc"</div><div><br></div><div>  so split("123abcabc456") should return [<<"123">>,<<"456">>]</div><div><br></div><div>So I thought I could use re for this:</div>


<div><br></div><div>> re:split("123abcabc456", "(abc)+").         </div><div>[<<"123">>,<<"abc">>,<<"456">>]</div><div><br></div><div>


<br></div><div>The manual page says the matching split string is not included in the</div><div>output - at least that what it appear to me to say.</div><div><br></div><div>How in the name of the great blue-eyed slimy thing that hides under stones</div>


<div>can I get rid of the additional <<"abc">> - this is totally not obvious to me.</div><div><br></div><div>try again:</div><div><br></div><div>> re:split("123abcabcabc456", "abc",[notempty]).</div>


<div>[<<"123">>,<<>>,<<>>,<<"456">>]</div><div><br></div><div><br></div><div>I was under the vague impression that <<>> *was* and empty string</div>


<div><br></div><div>I knew I hated regular expressions, can't they be outlawed?<span class="HOEnZb"><font color="#888888"><br></font></span></div><span class="HOEnZb"><font color="#888888"><div><br></div><div><br></div>

<div><br></div><div>/Joe</div></font></span></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>J.
</div>