Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Comment Removal

by saintmike (Vicar)
on Oct 16, 2005 at 18:26 UTC ( [id://500604]=note: print w/replies, xml ) Need Help??


in reply to Comment Removal

Your substitution looks for <-- (you might have wanted <!--) and then matches a single character that's not > or <, followed by -->. Probably not what you want.

A simple approach (although by no means 100% reliable) would be

$question =~ s/<!--.*?-->//sg;

To reliably remove comments from HTML, use HTML::Parser or a related module.

Or, even fancier, use File::Comments:

#!/usr/bin/perl -w use strict; use File::Comments; my $stripper = File::Comments->new(); my $stripped = $stripper->stripped("foo.html"); print "$stripped\n";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-03-28 17:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found