[erlang-questions] replace question

Wes James comptekki@REDACTED
Tue Apr 10 21:47:32 CEST 2012


I see in the documentation now that & has special meaning in erlang
re:replace.  I escaped that and now things are working properly.

-wes

On Tue, Apr 10, 2012 at 11:54 AM, Wes James <comptekki@REDACTED> wrote:
> I have the following code:
>
> f().
> S = <<"! *`-=[];',./~@#$%^&()_+{}|:\"<>?\\">>.
> RE = ["&","\\("].
> io:format("~n~s~n",[RE]).
> R="00&(00".
> io:format("~n~s~n",[R]).
> S2=re:replace(S, RE, R, [{return,list}, global, caseless]).
> io:format("~n~s~n",[S2]).
>
> produces "00&((00" instead of "00&(00" inside the string returned.
>
> f().
> S = <<"! *`-=[];',./~@#$%^&()_+{}|:\"<>?\\">>.
> RE = ["\\^","&"].
> io:format("~n~s~n",[RE]).
> R="00^&00".
> io:format("~n~s~n",[R]).
> S2=re:replace(S, RE, R, [{return,list}, global, caseless]).
> io:format("~n~s~n",[S2]).
>
> produces "00^^&00", instead of "00^&00" in the string returned.
>
> Can someone explain what I'm not escaping properly for this?
>
> Thanks,
>
> -wes



More information about the erlang-questions mailing list