Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: repeated characters in regular expressions

by kcott (Canon)
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

Replies are listed 'Best First'.
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 avoiding work at the Monastery: (10)
As of 2016-07-25 13:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?


















    Results (224 votes). Check out past polls.