[erlang-questions] replace question

Wes James <>
Tue Apr 10 19:54:53 CEST 2012


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