<div dir="ltr">I am trying to split by a regex, but I am getting the last two captures below, is there a way to get all captures?<div><br></div><div><div>1> re2:match(<<"a,b,c">>, <<"^(?:(\\w+)\\W+)*(\\w+)?$">>, [{capture,binary}]).</div>
<div><br></div><div>{match,[<<"a,b,c">>,<<"b">>,<<"c">>]}</div></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/12/23 Anthony Molinaro <span dir="ltr"><<a href="mailto:anthonym@alumni.caltech.edu" target="_blank">anthonym@alumni.caltech.edu</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>Well there is</div><div><br></div><div><span style="font-family:'.HelveticaNeueUI';font-size:15px;line-height:19px;white-space:nowrap"><a href="https://github.com/tuncer/re2" target="_blank">https://github.com/tuncer/re2</a></span></div>
<div><span style="font-family:'.HelveticaNeueUI';font-size:15px;line-height:19px;white-space:nowrap"><br></span></div><div><span style="font-family:'.HelveticaNeueUI';font-size:15px;line-height:19px;white-space:nowrap">It is a NIF and works really well, we've had it in production for a couple of years.</span></div>
<span class="HOEnZb"><font color="#888888"><div><span style="font-family:'.HelveticaNeueUI';font-size:15px;line-height:19px;white-space:nowrap"><br></span></div><div><span style="font-family:'.HelveticaNeueUI';font-size:15px;line-height:19px;white-space:nowrap">-Anthony</span></div>
</font></span><div><div class="h5"><div><br>On Dec 23, 2013, at 6:07 AM, Robert Virding <<a href="mailto:robert.virding@erlang-solutions.com" target="_blank">robert.virding@erlang-solutions.com</a>> wrote:<br><br></div>
<blockquote type="cite"><div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><hr><blockquote style="padding-left:5px;font-size:12pt;font-style:normal;margin-left:5px;font-family:Helvetica,Arial,sans-serif;text-decoration:none;font-weight:normal;border-left:2px solid #1010ff">
<b>From: </b>"Jesper Louis Andersen" <<a href="mailto:jesper.louis.andersen@gmail.com" target="_blank">jesper.louis.andersen@gmail.com</a>><br><div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">
On Sun, Dec 22, 2013 at 8:55 PM, Steve Vinoski <span dir="ltr"><<a href="mailto:vinoski@ieee.org" target="_blank">vinoski@ieee.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
You can gain a slight speedup by specifying [{return,binary}] as the final argument to re:split/3, but since you're splitting on whitespace, why not use binary:split rather than re:split? The former appears to be 10x faster than the latter for this case.</blockquote>
</div><br>This would be my approach as well. I tend to avoid regular expression parsing if I can. The speed of the regex library is probably quite dependent on the underlying regex engine. I would think the Ruby engine (Onigumuru IIRC) is faster than the nice PCRE engine Erlang uses. There are also the RE2 variant which uses a Thompson NFA and is faster for many problems. But it has no direct Erlang-implementation.</div>
</div></blockquote><div><br></div><div>It is faster and deterministic for any RE which needs backtracking; PCRE can backtrack into oblivion. There should definitely be an re2 module. It should be easier to implement as you don't have to worry about ensuring it doesn't block too long.<br>
</div><div><br></div><div>Robert<br></div><div><br></div></div></div></blockquote></div></div><div class="im"><blockquote type="cite"><div><span>_______________________________________________</span><br><span>erlang-questions mailing list</span><br>
<span><a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a></span><br><span><a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a></span><br>
</div></blockquote></div></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></div>