[erlang-questions] Stripping slashes from a string

Martin Dimitrov mrtndimitrov@REDACTED
Fri Apr 27 07:17:09 CEST 2012


Hello,

I have a string as the following:

"This is some\\r\\ntext"

I am trying to replace "\\r" with \r and "\\n" with \n.

I do it with the following two reg expressions:

R1 = re:replace(Result, "\\\\r", "\\\r", [{return,list}, global, unicode]),
R2 = re:replace(R1, "\\\\n", "\\\n", [{return,list}, global, unicode]),

Is there a better way? I tried to combine the two regex like:

re:replace(Result, "\\\\(r|n)", "\\\\1", [{return,list}, global, unicode])

but can't make it to work.

Thanks for looking at this.

Best regards,

Martin



More information about the erlang-questions mailing list