Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^3: how to search and replace the match with specific number of times in a string

by Ratazong (Monsignor)
on Jan 29, 2010 at 14:07 UTC ( [id://820357]=note: print w/replies, xml ) Need Help??


in reply to Re^2: how to search and replace the match with specific number of times in a string
in thread how to search and replace the match with specific number of times in a string

your code does 2 replaces:
  1. * will be replaced by *\n => so your string is    *\n*ab***c
  2. again, the first * will be replaced by *\n, giving you    *\n\n*ab***c
If you want to continue your approach, a solution could be:
  1. replace * by some string not containing your search-pattern (e.g. X) $s=~s{\*}{X} for 1..2;
  2. replace the new string by your search-pattern $s=~s{X}{\*\n} for 1..2;

Or follow some other advice given in this thread...

HTH, Rata

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-20 03:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found