Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Regex match iterative grouping

by sfink (Deacon)
on Apr 06, 2006 at 17:10 UTC ( #541674=note: print w/replies, xml ) Need Help??

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;

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://541674]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2023-03-21 08:10 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (59 votes). Check out past polls.