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

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

Thread Previous | Thread Next
From:
Abigail
Date:
January 27, 2012 07:07
Subject:
Re: [perl #109206] regexes: . different from [^\n]
Message ID:
20120127150656.GB22630@almanda
On Fri, Jan 27, 2012 at 06:40:09AM -0800, l.mai@web.de wrote:
> # New Ticket Created by  l.mai@web.de 
> # Please include the string:  [perl #109206]
> # in the subject line of all future correspondence about this issue. 
> # <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=109206 >
> 
> 
> 
> This is a bug report for perl from l.mai@web.de,
> generated with the help of perlbug 1.39 running under perl 5.14.2.
> 
> 
> -----------------------------------------------------------------
> [Please describe your issue here]
> 
> % perl -wle '$_ = "\n"; print $+[0] while /[^\n]*/g'
> 0
> 1
> 
> % perl -wle '$_ = "\n"; print $+[0] while /.*/g'    
> 0
> 
> I think this is a bug because in the absence of /s '.' should match any
> character except newline, i.e. be equivalent to '[^\n]'. The two programs
> should produce identical output.
> 
> I also think the first result is correct because there are two zero-length
> matches in "\n", one at the beginning of the string and one at the end.
> In conclusion: it looks like /.*/g is broken.


I agree. Note that if one makes the * possessive, it does give the 
same answer as when using [^\n]:

    $ perl -wE '$_ = "\n"; say scalar (() = /.*/g)'
    1
    $ perl -wE '$_ = "\n"; say scalar (() = /.*+/g)'
    2
    $


Abigail

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