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

Re^3: Perl RE; how to capture, and replace based on a block?

by AnomalousMonk (Abbot)
on Dec 18, 2013 at 01:39 UTC ( #1067568=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Perl RE; how to capture, and replace based on a block?
in thread Perl RE; how to capture, and replace based on a block?

I agree that use of an XML parser is likely to be a better idea, but just an example of what your fellow monks were hoping for as an example of what you tried and what resulted (except this works):

>perl -wMstrict -le "my $s = qq{xxx </div>\n</body> xxx}; print qq{[[$s]]}; ;; my $tags = qr{ </div> \n </body> }xms; $s =~ s{ $tags }{gone}xms; print qq{[[$s]]}; " [[xxx </div> </body> xxx]] [[xxx gone xxx]]

Question: Are you sure it's only a single newline that's present? The presence of other whitespace characters than just a newline can confuse the issue. The following might be a better regex:
    qr{ </div> \s* </body> }xms


Comment on Re^3: Perl RE; how to capture, and replace based on a block?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (15)
As of 2014-10-23 15:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (125 votes), past polls