[erlang-questions] Stripping slashes from a string

Martin Dimitrov mrtndimitrov@REDACTED
Fri Apr 27 11:28:58 CEST 2012


This is beautiful. Thank you.

On 4/27/2012 12:07 PM, Hynek Vychodil wrote:
> Wouldn't be this simple code far faster and simpler (especially
> compiled with HiPE):
>
> replace([$\\, $n | T]) -> [$\n, replace(T)];
> replace([$\\, $r | T]) -> [$\r, replace(T)];
> replace([H | T]) -> [H | replace(T)];
> replace([]) -> [].
>
> I'm always curious why people tend to use RE instead of few lines of
> very simple code especially in Erlang.
>
> Cheers
>   Hynek
>
> On Fri, Apr 27, 2012 at 9:28 AM, Martin Dimitrov <mrtndimitrov@REDACTED> wrote:
>> Hi,
>>
>> What I am trying to achieve is not to convert "\\\\n" to "\\n" but "\\n"
>> to [10].
>>
>> Martin
>>
>> On 4/27/2012 10:24 AM, Sergei Golovan wrote:
>>> On Fri, Apr 27, 2012 at 11:19 AM, Martin Dimitrov
>>> <mrtndimitrov@REDACTED> wrote:
>>>> With 6 it produces double backslashes making the result equivalent to
>>>> the initial text:
>>> True, I oversaw that the replacing regexp was incorrect too (also, the
>>> string itself).
>>>
>>> 1> re:replace("\\\\r \\\\n text", "\\\\\\\\(r|n)", "\\\\\\1",
>>> [{return,list}, global, unicode]).
>>> "\\r \\n text"
>>> 2>
>>>
>>> works fine.
>>>
>>> Cheers!
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list