in reply to Regex and \G

Where did you read about \G? perlre says " \G Match only at pos() (e.g. at the end-of-match position of prior m//g)" and that's what happens. After the first two matches, pos points at the letter X, and X is not a space, so the match fails.
my @lines = q[ X Y]; foreach(@lines){ s/\G {8}/warn pos();'G'/ge; } die qq['],@lines,q[']; __END__ 0 at - line 3. 8 at - line 3. 'GGX Y' at - line 5.
I can only assume that the first time it encounters a line, \G is set to 0 - i.e. the beginning of the line. Is this the case?
You don't have to assume, just use re 'debug'; and watch the output fly.

MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
** The third rule of perl club is a statement of fact: pod is sexy.

Replies are listed 'Best First'.
Re: Re: Regex and \G
by Melly (Chaplain) on Oct 23, 2003 at 09:36 UTC

    Sorry, I should have been clearer - I understand what \G (and my regex) does EXCEPT on the first match.

    I guess matching against the beginning of the string was the only possible option, but I just wanted to double-check.

    Just as well I did, or I'd never have know about "use re 'debug'" - many thanks.

    Tom Melly, tom@tomandlu.co.uk