On Sat Jan 28 13:27:55 2012, demerphq wrote: > On 28 January 2012 19:30, Lukas Mai <l.mai@web.de> wrote: > > On 2012-01-28 demerphq wrote: > > > >> You say that you consider "\n" to contain only one line. > >> > >> But what about "\nfoo". Does it contain one or two lines? Do you > >> expect ^ to match after the \n in "\nfoo"? If you do then do you > not > >> agree there is an inconsistency about it not matching after the \n > in > >> "\n"? > > > > "\nfoo" contains 1.5 lines, i.e. one complete (but empty) line and > one > > incomplete (unterminated) line. > > "\nfoo" =~ /^foo/m should match, yes. > > I don't think there's an inconsistency because \n is only the > beginning > > of a line if more text follows. That is, my model of /^/m > > is /(?:\A|(?<=\n)(?!\z))/. > > And the docs agree with you, perlre says this: > > You may, however, wish to treat a string as a multi-line buffer, > such that > the "^" will match after any newline within the string (except if > the newline > is the last character in the string), and "$" will match before any > newline. > > Though I do wonder if the "except if the newline is the last > character of the string" was a special case added later. Which is, interestingly (but irrelevantly), the way JavaScript does it: $ perl -MJE -le 'print new JE->eval(q|/\n^/m.test("\n")|)'true true (Or enter javascript:alert(/\n^/m.test("\n")) in a web browser.) In JavaScript, /^/m is equivalent to Perl’s /\A|(?<=[\cm\cj\x{2028}\x{2029}])/. -- Father Chrysostomos --- via perlbug: queue: perl5 status: open https://rt.perl.org:443/rt3/Ticket/Display.html?id=109206Thread Previous | Thread Next