From: Hugo <[EMAIL PROTECTED]>
Sent: Monday, September 11, 2000 11:59 PM


> mike mulligan replied to Peter Heslin:
> : ... it is greedy in the sense of the forward matching "*" or "+"
constructs.
> : [snip]
>
> This is nothing to do with greediness and everything to do with
> left-to-rightness. The regexp engine does not look for x* except
> in those positions where the lookbehind has already matched.

I was trying to understand at what point the lookbehind was attempted, and
confused myself and posted a bad example.  My apologies to everyone.  Let's
see if I can make sense of it on a second try.

My question is: if I have the regex  /(?<=[aeiou]X[yz]+/  then does Perl: 1.
scan first for 'X', test the lookbehind, and then test the '[yz]',  or 2.
scan for 'X[yz]' and then test the lookbehind?

I am expecting these two alternatives to give the same result, but certain
test strings might run slower or faster depending on the approach.

Running perl -Dr shows that alternative 1 is used:

qq(aXuhXvoXyz) =~ /(?<=[aeiou])X[yz]/

Guessing start of match, REx `(?<=[aeiou])X[yz]' against `aXuhXvoXyz'...
Found anchored substr `X' at offset 1...
Guessed: match at offset 1
Matching REx `(?<=[aeiou])X[yz]' against `XuhXvoXyz'
  Setting an EVAL scope, savestack=3
   1 <a> <XuhXvoXyz>      |  1:  IFMATCH[-1]
   0 <> <aXuhXvoXyz>      |  3:    ANYOF[aeiou]
   1 <a> <XuhXvoXyz>      | 12:    SUCCEED
                              could match...
   1 <a> <XuhXvoXyz>      | 14:  EXACT <X>
   2 <aX> <uhXvoXyz>      | 16:  ANYOF[yz]
                            failed...
  Setting an EVAL scope, savestack=3
   4 <aXuh> <XvoXyz>      |  1:  IFMATCH[-1]
   3 <aXu> <hXvoXyz>      |  3:    ANYOF[aeiou]
                              failed...
                            failed...
  Setting an EVAL scope, savestack=3
   7 <aXuhXvo> <Xyz>      |  1:  IFMATCH[-1]
   6 <aXuhXv> <oXyz>      |  3:    ANYOF[aeiou]
   7 <aXuhXvo> <Xyz>      | 12:    SUCCEED
                              could match...
   7 <aXuhXvo> <Xyz>      | 14:  EXACT <X>
   8 <aXuhXvoX> <yz>      | 16:  ANYOF[yz]
   9 <aXuhXvoXy> <z>      | 25:  END
Match successful!


Reply via email to