Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Comment Removal

by gube (Parson)
on Oct 17, 2005 at 04:58 UTC ( [id://500652]=note: print w/replies, xml ) Need Help??


in reply to Comment Removal


Hi, see the below code and correct your error. But, safe to remove the comment using File::Comments module

Update:
#!/usr/local/bin/perl $question = '<B>Hello World</B> <!-- This comment would need to be removed from the entry --> <font color=red>It is Sunday!</FONT>'; $question =~ s/<!--[^-]+-->//g; print $question; o/p: <B>Hello World</B> <font color=red>It is Sunday!</FONT>

Regards
Gube
$language = defined('perl') ? 'great :)' : 'die :(';

Replies are listed 'Best First'.
Re^2: Comment Removal
by rnahi (Curate) on Oct 17, 2005 at 06:02 UTC

    No, that's wrong either. If the comment contains a dash ('-') your regex won't remove it.

    use YAPE::Regex::Explain; print YAPE::Regex::Explain->new(qr(<!--[^-]+-->) )->explain(); __END__ The regular expression: (?-imsx:<!--[^-]+-->) matches as follows: NODE EXPLANATION ---------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------- <!-- '<!--' ---------------------------------------------------------- [^-]+ any character except: '-' (1 or more times (matching the most amount possible)) ---------------------------------------------------------- --> '-->' ---------------------------------------------------------- ) end of grouping ----------------------------------------------------------

    Example:

    $ perl -le '$_="<!--rm me--><p>good</p><!--rm-too-->";s/<!--[^-]+-->// +g;print' <p>good</p><!--rm-too-->

Log In?
Username:
Password:

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

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

    No recent polls found