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:
The output is:#!/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 -->
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.)BEFORE: <!-- comments --> snippet of code <!-- comments --> AFTER: snippet of code
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
|
|---|