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. 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 .. Regards, Sharan On 5/30/07, Chas Owens <[EMAIL PROTECTED]> wrote:
On 5/30/07, Sharan Basappa <[EMAIL PROTECTED]> wrote: > Hi All, > > I have some background working with scanners built from Flex. And I have > used lookahead capability of flex many a times. But I dont understand the > meaning of ZERO in zero lookahead match rule i.e. (?=pattern) snip I don't know jack about flex, so I can't help you with a comparison, but snip > The other question I have is - how does regex engine decide that it has to > move further its scanner by 1 character everytime snip 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;