in reply to Regex match iterative grouping

Adjust the quotes for your shell:

perl -le '$_ = "abcd"; while (/(..)/g) { print $1; --pos }'

Or closer to your exact question:

perl -le '$_ = "abcdefg"; while (/(...)/g) { print $1; pos($_) -= leng +th($1); pos($_)++ }'
You might be able to do that in a list-context match with an embedded expression, but that would be too scary for me.

Replies are listed 'Best First'.
Re^2: Regex match iterative grouping
by SamCG (Hermit) on Apr 06, 2006 at 19:39 UTC
    Thank you, both solutions work, though I will have to work on understanding Ido's a bit better.

    Note that as far as "adjusting my quotes to my shell", that technique doesn't work on my <Windows XP> shell. Inverting them (double-quotes surrounding all executable code, with either single quotes in the middle or escaped double-quotes) does work.


    -----------------
    s''limp';@p=split '!','n!h!p!';s,m,s,;$s=y;$c=slice @p1;so brutally;d;$n=reverse;$c=$s**$#p;print(''.$c^chop($n))while($c/=$#p)>=1; =1;