in reply to Re^2: Strange regex to test for newlines: /.*\z/
in thread Strange regex to test for newlines: /.*\z/

.* will match anything but a newline, or the empty string.

So I'd expect "foo\n" =~ /.*\z/; to match, but capture the empty string in $&, not "foo\n".

Of course there are more elaborate ways to match for a newline character ;-)

Replies are listed 'Best First'.
Re^4: Strange regex to test for newlines: /.*\z/
by mrpeabody (Friar) on May 22, 2007 at 20:37 UTC
    .* will match anything but a newline, or the empty string.

    It will match both of those, actually, as it should.

    506 $ perl -we'print "yes" if "" =~ /.*/' yes 507 $ perl -we'print "yes" if "\n" =~ /.*/' yes