in reply to Re: Pattern matching: Lazy vs. greedy
in thread Pattern matching: Lazy vs. greedy

Hello Athanasius, Thank you for your answer. I tried something like
my @matches = $string =~ /(the .*? dog)/gi;
before, which is without the (?= before the regex and the ) after it. This didn’t get me anywhere. I thought I was familiar with look-around assertions, but to be honest, I don’t get what the (?=) is doing here. I thought it is only used as a modification to something preceding it. I consulted http://perldoc.perl.org/perlre.html#Extended-Patterns but could not find why the two variants give different results. Could you explain that to me?

Replies are listed 'Best First'.
Re^3: Pattern matching: Lazy vs. greedy
by choroba (Cardinal) on Mar 30, 2015 at 12:51 UTC
    The point of using /(?=(the .*? dog))/gi here is that look around assertions are zero length, i.e. after they match at position P, the next match is not searched at their end, but at the position P + 1, so you can find overlapping matches, as well.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Thank you. Now I got it.