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 |