develooper Front page | perl.perl5.porters | Postings from January 2012

Re: [perl #109206] regexes: . different from [^\n]

Thread Previous | Thread Next
Lukas Mai
January 28, 2012 10:30
Re: [perl #109206] regexes: . different from [^\n]
Message ID:
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))/.

> Because to me that is the exact same thing as expecting /.*/ to match
> at the end of the string in "\n".
> So really the bug here is in ^ not in .*

That doesn't match my intuitive understanding of "beginning of line".

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About