Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: search and replace is not working as expected...

by mikeirw (Pilgrim)
on Nov 20, 2002 at 16:20 UTC ( #214518=note: print w/replies, xml ) Need Help??


in reply to search and replace is not working as expected...

I believe you want this:

$ARRGH =~ s#<doct>Customer trans\.(?:.*)+?</doct>#<doct>Customer trans\.</doct +>#g;

What the +? does is makes the match less "greedy", so that it matches the first </doct> it finds instead of the last. Also, since you aren't using what you capture in (.*), I put the ?: in, so that perl doesn't try to retain what it found, but still keeps the grouping.

I also changed the regex delimiter to | so that you don't have to escape the / in </doct>.

Update: As per Aristotle's reply, I've changed the regex delimiter to #.

Replies are listed 'Best First'.
Re^2: search and replace is not working as expected...
by Aristotle (Chancellor) on Nov 20, 2002 at 17:42 UTC
    I also changed the regex delimiter to | so that you don't have to escape the / in </doct>.
    Yuck, please use something else next time. | is a regex metacharacter, you just opened a can of worms.

    Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://214518]
help
Chatterbox?
[LanX]: What about Czech an Chechen ambessy?
[AnomalousMonk]: LanX: Rama had (has?) a high (much higher than typical asteroid) rate of axial (again, unusual, I think) spin for its artificial gravity.
LanX pity there is no Germs embassy ...
[choroba]: LanX We merged them to save money.
[LanX]: AnomalousMonk: yeah the asteroid but not the god, right?

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (14)
As of 2017-11-22 17:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (327 votes). Check out past polls.

    Notices?