[erlang-questions] adding slashes for special chars

Hynek Vychodil <>
Wed Jun 25 13:36:55 CEST 2008


It is little bit difficult. In regexp you have to escape backslash and
secondary must escape backslash for erlang parser but for substituting
string you have to only escape for erlang parser. Weird, so ...

5> {ok, T, _} = regexp:gsub("qwert\\asdf", "\\\\", "\\\\").
{ok,"qwert\\\\asdf",1}
6> io:format("~s~n", [T]).
qwert\\asdf
ok


2008/6/25 Andrey Shnayder <>:

> Hi, Erlang team.
> I want to add slashes before some characters in a string - single quote,
> double quote, backslash.
> I have not found any function that implement this, therefore I use
> regexp:gsub function, but I have a trouble with backslashes:
>
> *69> regexp:gsub("qwert\\asdf", "\\", "\\\\").
> {error,{unterminated,"\\"}}*
>
> May you help me, please?
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



-- 
--Hynek (Pichi) Vychodil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080625/27cc694c/attachment.html>


More information about the erlang-questions mailing list