Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Replacing a given character starting with the xth occurence in a string

by tachyon (Chancellor)
on May 21, 2001 at 04:33 UTC ( [id://81889]=note: print w/replies, xml ) Need Help??


in reply to Replacing a given character starting with the xth occurence in a string

Here is a different way using progressive matching and the \G assertion to continue matching from that point. TIMTOWTDI

tachyon

my $nth = 3; my $rep = 1; my $chr = 'e'; my $str = "Terence and Philip are sweet"; $str =~ m/$chr/gc for (1..$nth); # eat up first $nth "$chr"s $str =~ s/\G(.*?)$chr/$1$rep/g; # replace the rest print $str;
  • Comment on Re: Replacing a given character starting with the xth occurence in a string
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://81889]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-18 18:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found