At 09:36 PM 6/13/02 -0700, Paul Makepeace wrote:
>Can someone explain the first result?
>
>$ perl -wle '$_ = "small - medium - large";
>     /- (.+?)$/;   print $1;
>     /^(.+?) -/;   print $1;
>     /.*- (.+?)$/; print $1'
>medium - large
>small
>large
>$
>
>I was expecting just "large" with the non-greedy match. In light of
>result #1, I contrived #3, but I'm not completely sure why it's
>necessary.

You're suffering from regex myths.  Take two Jeff Friedls and call us in 
the morning :-)

Considering #1:

-<SPC>          Move from left to right until you find those characters
..+?             Match at least one character that isn't a newline,
                 followed by as few of them as necessary for the
                 rest of the match to succeed
$               Match end of string or newline at end of string

Clearer now?

I would probably have written

         /([^-]+)$/

--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com/

Reply via email to