[erlang-questions] Stripping slashes from a string

Martin Dimitrov mrtndimitrov@REDACTED
Fri Apr 27 09:04:46 CEST 2012


Hi,

I am not sure what it works for you. See what I get:

(dilbert@REDACTED)16> re:replace("\\r \\n text", "\\\\(r|n)", "\\\\1",
[{return,list}, global, unicode]).
"\\1 \\1 text"
(dilbert@REDACTED)17>

Best regards,

Martin

On 4/27/2012 9:34 AM, Michael Turner wrote:
> Works for me, Martin. Maybe you need to write the result with ~s
> rather than ~p? E.g.
>
>    io:format ("~s", R2);
>
> Made that mistake myself ....
>
> -michael turner
>
>
> On Fri, Apr 27, 2012 at 2:17 PM, Martin Dimitrov <mrtndimitrov@REDACTED> wrote:
>> 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
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list