![]() |
|
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?? |
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.
In Section
Seekers of Perl Wisdom
|
|