Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: look-ahead greed changed between perl releases?

by amon (Scribe)
on May 06, 2014 at 18:05 UTC ( #1085215=note: print w/replies, xml ) Need Help??


in reply to look-ahead greed changed between perl releases?

You are mistaken in your assumption that the observed lookahead-behavior would be incorrect. Both the + and the {2,} are as greedy as they are outside of lookaheads, but the lookahead matches repeatedly because it doesn't consume any characters by itself.

Let's play the manual regex engine game:

""."string-N-U-M-B-E-R-O-N-E" MATCH($1="string-N-U-M-B-E-R-O-N-") "%s"."tring-N-U-M-B-E-R-O-N-E" MATCH($1="tring-N-U-M-B-E-R-O-N-") "%s%t"."ring-N-U-M-B-E-R-O-N-E" MATCH($1="ring-N-U-M-B-E-R-O-N-") "%s%t%r"."ing-N-U-M-B-E-R-O-N-E" MATCH($1="ing-N-U-M-B-E-R-O-N-") "%s%t%r%i"."ng-N-U-M-B-E-R-O-N-E" MATCH($1="ng-N-U-M-B-E-R-O-N-") "%s%t%r%i%n"."g-N-U-M-B-E-R-O-N-E" MATCH($1="g-N-U-M-B-E-R-O-N-") "%s%t%r%i%n%g"."-N-U-M-B-E-R-O-N-E" MATCH($1="-N-U-M-B-E-R-O-N-") "%s%t%r%i%n%g%-"."N-U-M-B-E-R-O-N-E" MATCH($1="N-U-M-B-E-R-O-N-") "%s%t%r%i%n%g%-%N"."-U-M-B-E-R-O-N-E" MATCH($1="-U-M-B-E-R-O-N-") ... "%s%t%r%i%n%g%-%N%-%U%-%M%-%B%-%E%-%E%-%R"."-O-N-E" MATCH("-O-N-E") "%s%t%r%i%n%g%-%N%-%U%-%M%-%B%-%E%-%E%-%R%-"."O-N-E" FAIL "%s%t%r%i%n%g%-%N%-%U%-%M%-%B%-%E%-%E%-%R%-O-N-E"."" FAIL

Replies are listed 'Best First'.
Re^2: look-ahead greed changed between perl releases?
by AnomalousMonk (Chancellor) on May 07, 2014 at 04:31 UTC

    Another variation:

    c:\@Work\Perl>perl -wMstrict -le "print $]; ;; my $s = 'ABCDEF'; ;; my @captures = $s =~ m{ (?= (.{3,})) }xmsg; printf qq{'$_' } for @captures; " 5.014004 'ABCDEF' 'BCDEF' 'CDEF' 'DEF'

    Interestingly, this particular example works exactly the same for all the regex expressions  (.{3,}) and  (.+) and  (.{1,}) on all the Perl versions I have in captivity (all Win32): ActiveState 5.8.9 and Strawberries 5.10.1.5, 5.12.3.0 and 5.14.4.1.
    (Of course, output differs between  (.{3,}) and  (.{1,}) but the latter and  (.+) are the same.)

Re^2: look-ahead greed changed between perl releases?
by raygun (Beadle) on May 06, 2014 at 18:47 UTC
    Thanks, amon, for the detailed illustration.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1085215]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2019-05-23 01:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (140 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!