[erlang-questions] Why is it necessary to "double-escape" [ characters in regular expressions?

Gaspar Chilingarov nm@REDACTED
Mon Mar 30 08:57:40 CEST 2009


Hello!

Let's try on the simple example

2> "\q".
"q"
3> "\\q".
"\\q"

But do really "\\q" means 3 symbols or 2 ?

6> lists:map(fun(X) -> erlang:display(X) end, "\\q").
92
113
[true,true]

Well. So it's in your regular expression you put exactly 2 characters -
\ and [
which is required by a regexp to interpret [ as a character and not as 
class start symbol.

So it works quite predictable ;)

/Gaspar

-- 
Gaspar Chilingarov

tel +37493 419763 (mobile - leave voice mail message)
icq 63174784
skype://gasparch
e mailto:nm@REDACTED mailto:gasparch@REDACTED
w http://gasparchilingarov.com/



More information about the erlang-questions mailing list