On Wed, Apr 30, 2008 at 04:49:03PM +0200, Bram wrote: > Quoting James Mcclure <perlbug-followup@perl.org>: > > > ># perl zero-length regex bug > > > ># instructions: > ># 1) run with $ARGV[0] = 1, this script prints false > ># 2) run with $ARGV[0] = 2, this script prints true > ># 3) comment out the $ARGV[0] =~ /1/ line --> this script prints true > >$ARGV[0] =~ /1/; > >if ( '' =~ // ) { print "true\n"; } > >else { print "false\n"; } > > > >----------------------------------------------------------------- > > Hello, > > Thank you for your bug report but this is not a bug. > > > If you use an empty pattern after a re then it uses the pattern of the > last succesful match. > > It is mentioned in > http://perldoc.perl.org/perlretut.html#Using-regular-expressions-in-Perl > > > But perhaps it could/should be documented more clearly... (I can't > easily find it in perlre for example - or atleast not using a basic > search) From perlop: If the PATTERN evaluates to the empty string, the last success- fully matched regular expression is used instead. In this case, only the "g" and "c" flags on the empty pattern is honoured - the other flags are taken from the original pattern. If no match has previously succeeded, this will (silently) act instead as a genuine empty pattern (which will always match).Thread Previous | Thread Next