Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: repeated characters in regular expressions

by kcott (Abbot)
on Aug 01, 2013 at 08:03 UTC ( #1047388=note: print w/ replies, xml ) Need Help??


in reply to repeated characters in regular expressions

G'day AmnonM,

Welcome to the monastery.

If you decrement the 'n' value, you can do this:

s/(.)\1{$n}/$1 x $m/eg;

Here's my test:

$ perl -Mstrict -Mwarnings -E ' sub mod_char_count { my ($n, $m, $x) = @{+shift}; --$n; $x =~ s/(.)\1{$n}/$1 x $m/eg; return $x; } my @data = ( [4, 1, "p8888er9999l"], [1, 3, "monks"], ); say mod_char_count($_) for @data; ' p8er9l mmmooonnnkkksss

-- Ken


Comment on Re: repeated characters in regular expressions
Select or Download Code
Re^2: repeated characters in regular expressions
by AmnonM (Initiate) on Aug 01, 2013 at 08:10 UTC
    Thanks to all. I'll try these implementations.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (13)
As of 2014-10-24 17:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (134 votes), past polls