Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Re: Removing html comments with regex

by esh (Pilgrim)
on Aug 23, 2003 at 06:33 UTC ( [id://286019]=note: print w/replies, xml ) Need Help??


in reply to Re: Removing html comments with regex
in thread Removing html comments with regex

You have provided a regular expression and some sample data. You say that the regular expression removes "snippet of code" from your sample data, but it does not.

Here, I've adapted blokhead's framework and plugged in your regular expression and your data:

#!/usr/bin/perl -w use strict; my $comments = do { local $/; <DATA> }; print "BEFORE:\n$comments"; $comments =~ s/<!--(.|\s)*?-->//g; print "AFTER:\n$comments"; __DATA__ <!-- comments --> snippet of code <!-- comments -->
The output is:
BEFORE: <!-- comments --> snippet of code <!-- comments --> AFTER: snippet of code
If you want to have someone debug your problem, you'll have to provide the real regular expression you're using or the real data. (And, yes, I did test it out with multi-line comments, too.)

BTW, $comments is a little strange as a name for text which includes more than just comments. Are you sure that it contains the snippet of code before you apply the regular expression?

-- Eric Hammond

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-20 08:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found