S
Sandman
Let's say I have a string that goes like this:
"A horse is a horse is a horse, on a horseman"
and I want to count how many "horse" there is in the string. Well, that's easy,
by using:
$_ = "A horse is a horse is a horse, on a horseman";
my $nr;
$nr++ for /horse/ig;
print $nr;
__END__
Out: 4
Now, I would like add a number to each word that contains the string horse, and
this is where I am lost.
Basically, what I want to output is this:
"A horse (1) is a horse (2) is a horse (3), on a horseman (4)"
Note that it should be "horseman (4)" not "horse (4)man".
Anyone got a juicy regexp for this?
"A horse is a horse is a horse, on a horseman"
and I want to count how many "horse" there is in the string. Well, that's easy,
by using:
$_ = "A horse is a horse is a horse, on a horseman";
my $nr;
$nr++ for /horse/ig;
print $nr;
__END__
Out: 4
Now, I would like add a number to each word that contains the string horse, and
this is where I am lost.
Basically, what I want to output is this:
"A horse (1) is a horse (2) is a horse (3), on a horseman (4)"
Note that it should be "horseman (4)" not "horse (4)man".
Anyone got a juicy regexp for this?