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

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

Thread Previous | Thread Next
From:
Lukas Mai
Date:
January 28, 2012 10:30
Subject:
Re: [perl #109206] regexes: . different from [^\n]
Message ID:
20120128193009.2fc6e64a@web.de
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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About