<div dir="ltr">Thanks. I am trying to get all captures for my first group (\\w+) which is inside the non-capturing group, and I am getting only the last capture. for this specific example I need to get [<<"a">>,<<"b">>,<<"c">>]<div>
<br></div><div>konstantin</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/12/28 Robert Virding <span dir="ltr"><<a href="mailto:robert.virding@erlang-solutions.com" target="_blank">robert.virding@erlang-solutions.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><div>You are getting all the captures. By default the whole match is considered to be the first capture. If you don't want this then do:<br>
</div><div><br></div><div><div><div>1> re2:match(<<"a,b,c">>, <<"^(?:(\\w+)\\W+)*(\\w+)?$">>, [{capture,all_but_first,binary}]).</div><div>{match,[<<"b">>,<<"c">>]}</div>
</div></div><div><br></div><div>It mimics the re module in many ways.<br></div><div><br></div><div>Robert<br></div><div><br></div><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>"akonsu" <<a href="mailto:akonsu@gmail.com" target="_blank">akonsu@gmail.com</a>><br><b>To: </b>"Anthony Molinaro" <<a href="mailto:anthonym@alumni.caltech.edu" target="_blank">anthonym@alumni.caltech.edu</a>><br>
<b>Cc: </b>"Robert Virding" <<a href="mailto:robert.virding@erlang-solutions.com" target="_blank">robert.virding@erlang-solutions.com</a>>, "erlang-questions" <<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a>>, "Steve Vinoski" <<a href="mailto:vinoski@ieee.org" target="_blank">vinoski@ieee.org</a>><br>
<b>Sent: </b>Thursday, 26 December, 2013 6:42:19 PM<br><b>Subject: </b>Re: [erlang-questions] any way to speed up regex.split?<div><div class="h5"><br><div><br></div><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><div><br></div><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><br>
</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><span style="color:#888888" 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>
</span></span><div><div><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><div><br></div></div>
<blockquote><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><blockquote><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" target="_blank">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>
</div></div></blockquote><div><br></div></div></div></blockquote></div><br></div>