Re: zero width lookahead match

2007-06-01 Thread John W. Krahn
Rob Dixon wrote: As far as lookahead expressions are concerned, Perl functions identically to Flex. It is called zero-width lookahead because it matches a zero-width /position/ in the string instead of a sequence of characters. If I write '123456' =~ /\d\d\d(...)/ then '456' will be

Re: zero width lookahead match

2007-05-31 Thread jeevs
$ perl -wle' $string = abc; while ($string =~ /(.*?)/g) { print pos($string), : , $1;} ' 0: 1: a 1: 2: b 2: 3: c 3: Can someone explain the working of the g modifier since my knowledge of using g was to use it for substituting globally... Here i get what paul is trying to explain

Re: zero width lookahead match

2007-05-31 Thread Sharan Basappa
Its the same logic - continue after first substitution/match. In case of subst.. it continues and in case of regex, the search continues after first match until the complete string is exhausted On 30 May 2007 22:54:39 -0700, jeevs [EMAIL PROTECTED] wrote: $ perl -wle' $string = abc; while

zero width lookahead match

2007-05-30 Thread Sharan Basappa
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) For example, to capture overlapping 3 digit patterns from string $str = 123456

Re: zero width lookahead match

2007-05-30 Thread Chas Owens
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

Re: zero width lookahead match

2007-05-30 Thread Chas Owens
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 You may also prefer

Re: zero width lookahead match

2007-05-30 Thread Sharan Basappa
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

Re: zero width lookahead match

2007-05-30 Thread Chas Owens
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

Re: zero width lookahead match

2007-05-30 Thread Rob Dixon
Sharan Basappa 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) For example, to capture overlapping 3 digit patterns

Re: zero width lookahead match

2007-05-30 Thread Sharan Basappa
Thanks Rob and Chas .. On 5/30/07, Rob Dixon [EMAIL PROTECTED] wrote: Sharan Basappa 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

Re: zero width lookahead match

2007-05-30 Thread Paul Lalli
On May 30, 10:02 am, [EMAIL PROTECTED] (Chas Owens) wrote: On 5/30/07, Sharan Basappa [EMAIL PROTECTED] wrote: 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

Re: zero width lookahead match

2007-05-30 Thread Chas Owens
On 30 May 2007 08:53:54 -0700, Paul Lalli [EMAIL PROTECTED] wrote: snip I got confused by this too. I think Sharan's question comes down to why isn't this an infinite loop? That is, why does pos() move ahead one character when it matches 0 characters? This is not limited to look-ahead