[erlang-questions] splitting binaries on a separator

Colm Dougan colm.dougan@REDACTED
Thu May 28 19:22:59 CEST 2009

On Thu, May 28, 2009 at 2:17 PM, Joel Reymont <joelr1@REDACTED> wrote:
> Is there a more efficient way of splitting binaries on a separator sequence?

If your Sep is well known and you don't mind compiling it then it may
be faster to use the 're' module

split_bin2(RE, Bin) ->
    case re:run(Bin, RE) of
        {match,[{Offset,Len}]} ->
            <<Before:Offset/binary, _:Len/binary, After/binary>> = Bin,
            [Before, After];
        _ ->

Where you have earlier compiled RE as :

   {ok, RE} = re:compile(Sep)


More information about the erlang-questions mailing list