[erlang-questions] Smart way to trim a binary?

Seth Falcon seth@REDACTED
Wed Jun 24 16:03:24 CEST 2009


* On 2009-06-24 at 14:40 +0200 Ulf Wiger wrote:
> BTW, regarding the trimming of binaries, perhaps someone
> with more regexp skill could improve on this:
>
> 1> re:split(<<"  \tabc\t  ">>, "[(^\\h*)(\\h$)]",[trim]).
> [<<>>,<<>>,<<>>,<<"abc">>]

Perhaps:

trimre(Bin) ->
    re:replace(Bin, "^\\s+|\\s+$", "", [{return, binary}, global]).

+ seth


More information about the erlang-questions mailing list