Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Regexp: can I do it in one go?

by Arien (Pilgrim)
on Aug 22, 2002 at 11:31 UTC ( [id://191986]=note: print w/replies, xml ) Need Help??


in reply to Regexp: can I do it in one go?

What you want to do is globally match a something including possible repetitions, and replace what you've found with that something followed by the length of your match:

$s =~ s/((.)\2*)/$2 . length $1/eg;

— Arien

Edit: It seems I misread the output you want. To only have sequences of two or more repeated letters replaced, change the star to a plus sign. (And after some sleep...) Also, you'd want to swap length $1 and $2 to have the length preceed the letter.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2025-02-09 00:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (95 votes). Check out past polls.