Hi,<br><br>Erlang doesn't eat up the backslash character in strings, it is a quote character which is used to put "special" characters in a string. For example \t becomes a TAB and \n a newline character. \\ becomes simply the \ character.<br>

<br>This why the string "\\." becomes the regular expression '\.' and the string "\\\\." becomes the string '\\.'.<br><br>I think the reason for this behaviour is that the underlying regular expression implementation, PCRE, also uses the \ character as a quote character in it's strings so your original replacement string '\.' is interpreted as just a '.'. You therefore need an extra \ in the replacement string which is why it must be "\\\\." in Erlang. You are getting a double string treatment.<br>

<br>This is not the same in the regular expression as you have noted.<br><br>Again this straight off the top of my head but would explain the behaviour.<br><br>Robert<br><br><div class="gmail_quote">2009/5/12 Attila Rajmund Nohl <span dir="ltr"><<a href="mailto:attila.r.nohl@gmail.com">attila.r.nohl@gmail.com</a>></span><br>

<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hello!<br>
<br>
I'd like to replace all dot characters in a string with backslash-dot<br>
sequences. My first try was<br>
<br>
re:replace("f.e.l.", "\\.", "\\.", [{return, list}, global])<br>
<br>
Because Erlang "eats up" the backslash characters, the actual regular<br>
expression in the second argument is "\." which is exactly what I<br>
want. For the same reason the actual replacement string is also "\."<br>
which is also what I want. However, the result is not what I expected:<br>
<br>
> re:replace("f.e.l.", "\\.", "\\.", [{return, list}, global]).<br>
"f.e.l."<br>
<br>
When I added a couple of more backslashes to the replacement string, I<br>
got what I wanted:<br>
<br>
> re:replace("f.e.l.", "\\.", "\\\\.", [{return, list}, global]).<br>
"f\\.e\\.l\\."<br>
<br>
but I don't understand why I need four backslashes instead of two. Any<br>
light on this issue?<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div><br>