[erlang-questions] replace Result error

Sergei Golovan sgolovan@REDACTED
Mon Dec 1 11:55:50 CET 2014


Hi Sanath,

On Mon, Dec 1, 2014 at 1:49 PM, Sanath Prasanna <ahe.sanath@REDACTED> wrote:
> Hi,
>  I used following & return wrong result. How can I correct that ?
>
>
> re:replace("stop Ads ? <user_opt_out_keyword> to 1111",
> "<user_opt_out_keyword>", "pair&lovely", [{return,list}, global]).
> Result => "stop Ads ? pair<user_opt_out_keyword>lovely to 1111"

& in substitution pattern means "the matching string". To insert the literal &
you'll have to escape it. Try

re:replace("stop Ads ? <user_opt_out_keyword> to
1111","<user_opt_out_keyword>", "pair\\&lovely", [{return,list},
global]).

(the second backslash is necessary because otherwise it escapes the
following & and vanishes).

Cheers!
-- 
Sergei Golovan



More information about the erlang-questions mailing list