Finalfire wrote:
Hello guys! I'm skilling regex using Perl and i've some trouble about
a simple try:
i've a string like:

$string = "HELLOOOOAAABBCCCC";

and i want to manipulate in that way: HELL4O3ABB4C;You can simply
notice that when i have 3 or more occurrences of a character, i want
to substitute all the occurrences and write "nC" where n is how times
the character C is found on a string.

So, in regex (i think there are so many way to do it but i wish to do
with regex, just skilling...) i write:

$string =~ s/(.)\1\1+/$1/;

but how can i get the number of the occurrences in the string of that
pattern?

my $string = "HELLOOOOAAABBCCCC";
print "$string\n";

$string =~ s/((.)\2\2+)/length($1).$2/ge;
print "$string\n";

See:
perldoc perlretut  http://perldoc.perl.org/perlretut.html
perldoc perlre     http://perldoc.perl.org/perlre.html


--
Just my 0.00000002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

Eliminate software piracy:  use only FLOSS.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to