regexp bug (literal dot)

Anders Ramsell <>
Tue Mar 26 00:48:28 CET 2002


Willem Broekema wrote:

> Hi all,
> 
>  From what I understand, in regexps, "." means 'any char' and "\." means 
> a literal dot.
> 
> So, the following is a bug:
> 
> 170> regexp:match("a", ".").
> {match,1,1}
> 
> 171> regexp:match("a", "\.").
> {match,1,1}  % shouldn't match!
> 


I don't think your problem is a bug in regexp. The problem is a mistake 
in using backslash-quoting in string literals. The string literal "\." 
is actually the same as the string literal ".". To get a string literal 
representing a string with a backslash and a dot you need to write 
"\\.". This is illustrated by the following tests:

 > string:len(".").
1
 > string:len("\.").
1
 > string:len("\\.").

2


As you can see the first two string literals represent strings of length 
one and the third represents a string of length two.

/Anders





More information about the erlang-questions mailing list