Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
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
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 about the Monastery: (17)
As of 2015-07-28 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (255 votes), past polls