|Don't ask to ask, just ask|
Strange regex to test for newlines: /.*\z/by betterworld (Curate)
|on May 21, 2007 at 12:25 UTC||Need Help??|
betterworld has asked for the
wisdom of the Perl Monks concerning the following question:
apparently, /.*\z/ tests whether a string ends in a newline:
I find this very strange. In my opinion, this regular expression should always match. Every string, even "foo\n", has an end (\z), and since .* matches zero or more horizontal characters, it should always match the empty string before the end of the string. However, it doesn't, as you can see in the first one-liner.
I've tested it in perl versions 5.8.8, 5.005_03 and 5.9.4.
Update: This perl bug is now fixed (see below). Thanks to demerphq.