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

Re^3: Removing XML comments with regex

by gamache (Friar)
on Oct 24, 2007 at 19:37 UTC ( [id://646980]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Removing XML comments with regex
in thread Removing XML comments with regex

You're right about the minimal match on .*?, but keep /s in there or it will miss multiline comments.
$xml =~ s/<!--.*?-->//sg;

Replies are listed 'Best First'.
Re^4: Removing XML comments with regex
by tuxz0r (Pilgrim) on Oct 24, 2007 at 19:41 UTC
    Right on,
    s/<!--.*?-->//gs
    is the proper way to go, since we don't want to be greedy and treat the beginning of the first comment until the end of the last comment as a giant comment itself.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-16 12:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found