Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Regex match iterative grouping

by sfink (Deacon)
on Apr 06, 2006 at 17:10 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-24 17:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found