Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Advanced replace function

by ikegami (Patriarch)
on Dec 04, 2009 at 19:49 UTC ( [id://811153]=note: print w/replies, xml ) Need Help??


in reply to Re: Advanced replace function
in thread Advanced replace function

There was nothing about newlines being disallowed in the brackets. The following is faster and more likely to match correctly:
s/\[.*?\]/~~/sg

But that's risky, especially if you use it a larger pattern. The /.*?/ could match a "[" or a "]". That's obviously undesirable. The following pattern avoids that problem:

s/\[[^\[\]]*\]/~~/g;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-03-29 07:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found