<div dir="ltr">According to the docs re:replace returns <span class="gmail-bold_code gmail-bc-2">iodata | list | binary</span><div><span class="gmail-bold_code gmail-bc-2">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).</span></div><div><span class="gmail-bold_code gmail-bc-2"><br></span></div><div><span class="gmail-bold_code gmail-bc-2">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.</span></div><div><span class="gmail-bold_code gmail-bc-2"><br></span></div><div><span class="gmail-bold_code gmail-bc-2"><span style="font-family:monospace"><span style="color:rgb(0,0,0);background-color:rgb(255,255,255)">1> S = <<"fml.ölm vcrd rd hb kh ouniun">>.                           </span><br><<"fml.ölm vcrd rd hb kh ouniun">>
<br>2> {ok, Re} = re:compile(<<>>, [unicode, caseless]).   <br>{ok,{re_pattern,0,1,0,
<br>                <<69,82,67,80,71,0,0,0,1,8,0,0,1,0,0,0,255,255,255,255,
<br>                  255,255,...>>}}
<br>3> re:replace(S, Re, <<>>,  [global, {return, binary}]).
<br>{error,<<"fml.">>,<<"ölm vcrd rd hb kh ouniun">>}
<br>4> re:replace(S, <<>>, <<>>,  [global, {return, binary}]).
<br><<"fml.ölm vcrd rd hb kh ouniun">><br>
<br></span><br></span></div><div><span class="gmail-bold_code gmail-bc-2"><br></span></div></div>