Melly has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monkees,
Now, this actually does what I want:
foreach(@lines){ s/\G {8}/\t/g; }
It replaces multiples of 8 spaces with the corresponding number of tabs, but only at the beginning of the line. In other words, with a line like:
X Y
it only replaces the spaces between the start of the line and X, but leaves the spaces between the X and Y alone.
My question is, how?
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex and \G
by broquaint (Abbot) on Oct 23, 2003 at 09:16 UTC | |
|
Re: Regex and \G
by PodMaster (Abbot) on Oct 23, 2003 at 09:15 UTC | |
by Melly (Chaplain) on Oct 23, 2003 at 09:36 UTC | |
|
Re: Regex and \G
by Abigail-II (Bishop) on Oct 23, 2003 at 09:14 UTC | |
by Melly (Chaplain) on Oct 23, 2003 at 09:20 UTC | |
by tye (Sage) on Oct 23, 2003 at 14:38 UTC | |
by Abigail-II (Bishop) on Oct 23, 2003 at 14:45 UTC | |
|
Re: Regex and \G
by bart (Canon) on Oct 24, 2003 at 01:02 UTC |