On 5/30/07, Sharan Basappa <[EMAIL PROTECTED]> wrote:
>> this is what the zero-width lookahead assertion means.  It say with
>>out moving where you are currently starting the match, make certain
>>you can match the following pattern.  If you want it to move where the
>>match starts then you have to include something that does not have
>>zero-width like this

>> #match groups of three characters followed by three characters: "123" and
"456"
>> @store = $str =~ m/(\d\d\d)(?=\d\d\d)/g;

You mention that if I write a rule like @store = $str =~ m/((?=\d\d\d))/g;
then the scanner does not move ahead. But as I mentioned in my mail,
the result of this regex is 123 234 etc. This clearly shows that after every
match,
the regex engine of perl is moving its pointer to next char in the string
(i.e. it starts
looking at 23456 once 123 is matched)
This was exactly my question.
snip

Because it always moves ahead by either one character or the match,
but zero-width constructs do not consume any characters.  That is why
they are called zero-width.

snip
Regarding the other question about comparing with Flex, actually there is
no need to compare with flex. What I was trying to understand is, why is
that
it is called zero lookahead rule when the number of chars it looks ahead
depends
on the rule I write. For example, the regex in the above rule looks ahead 3
chars
ahead to find a match ..
snip

Because it is not called zero lookahead, it is called zero-width
positive lookahead assertion, that is it consumes zero characters from
the string while at the same time causing the match to fail if the
assertion does not match.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to