[erlang-questions] replace bug or error in the documentation

John Doe donpedrothird@REDACTED
Wed Apr 18 23:57:19 CEST 2018


According to the docs re:replace returns iodata | list | binary
But sometimes with I think invalid unicode (see below) it returns {error,
binary(), binary()} - the same error which would return
unicode:characters_to_list(Binary, utf8).

I would say that it is an error in the docs, but it happens only when the
Search parameter is a compiled regexp. With regexp as string it returns
binary. So I think it is a bug.

1> S = <<"fml.ölm vcrd rd hb kh ouniun">>.
<<"fml.ölm vcrd rd hb kh ouniun">>
2> {ok, Re} = re:compile(<<>>, [unicode, caseless]).
{ok,{re_pattern,0,1,0,
               <<69,82,67,80,71,0,0,0,1,8,0,0,1,0,0,0,255,255,255,255,
                 255,255,...>>}}
3> re:replace(S, Re, <<>>,  [global, {return, binary}]).
{error,<<"fml.">>,<<"ölm vcrd rd hb kh ouniun">>}
4> re:replace(S, <<>>, <<>>,  [global, {return, binary}]).
<<"fml.ölm vcrd rd hb kh ouniun">>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180419/9dfd599b/attachment.htm>


More information about the erlang-questions mailing list