Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Search and replace in portion of xml file

by kennethk (Abbot)
on Jun 01, 2009 at 14:25 UTC ( #767265=note: print w/replies, xml ) Need Help??


in reply to Search and replace in portion of xml file

Your best bet, as toolic and apl suggest, is to use an XML parser. Manually parsing XML is fraught with potential bugs and edge cases. However, assuming your XML is well-formed, you can accomplish this task using Look Around Assertions. Specifically, if you assume that your text field contains no < characters, you can do it with

s/EM(?=[^<]*</article>)/replacement/g.

This will match and replace any occurence of the letters EM that are followed by any number of non-< characters and then a closing article tag.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://767265]
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: (6)
As of 2023-12-08 15:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (36 votes). Check out past polls.

    Notices?