Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
The above code finds a repeated character only once i.e. the "o" after "F". If it is repeated again it is being ignored in this case the "o"s after b. How to find the all the repeated characters and have them substituted. Thanksmy $str = "Foooboooobaaar"; while($str =~ /(\w)(\1+)/gi) { print "\nInside while concat_str -- $1 ---- $2 ---> $1.$2"; $str_concat = $1.$2; $str_rep_concat = $1.'*'; $str=~ s/$str_concat/$str_rep_concat/gi; } print "\n$str";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Replace repeated characters with *
by GrandFather (Saint) on Jul 03, 2009 at 11:44 UTC | |
by Anonymous Monk on Jul 03, 2009 at 11:50 UTC |