pombreda / re2

Automatically exported from code.google.com/p/re2
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

$ does not match \n at end of string #33

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In Perl and PCRE matching "foo\n" against /foo$/ is true, however in RE2 this 
is false.

It seems RE2 does not let $ match a \n unless it is in multi line matching mode.

$ perl -le'print "foo\n" =~ /foo$/ ? "true" : "false"'
true
$ perl -Mre::engine::PCRE -le'print "foo\n" =~ /foo$/ ? "true" : "false"'
true
$ perl -Mre::engine::RE2 -le'print "foo\n" =~ /foo$/ ? "true" : "false"'
false

(Note the RE2 in re::engine::RE2 is slightly patched, but nothing that affects 
this).

Original issue reported on code.google.com by dgl...@gmail.com on 29 Jan 2011 at 4:47

GoogleCodeExporter commented 9 years ago
Yes, this is an incompatibility between Perl and RE2.
RE2 only does single-byte lookahead, so in Perl terms
it implements (?-m)$ as \z not \Z.

I have updated the syntax page to make this explicit
http://code.google.com/p/re2/wiki/Syntax

Original comment by rsc@swtch.com on 30 Jan 2011 at 6:39