Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Comment Removal

by rnahi (Curate)
on Oct 17, 2005 at 06:02 UTC ( #500662=note: print w/ replies, xml ) Need Help??


in reply to Re: Comment Removal
in thread Comment Removal

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-->


Comment on Re^2: Comment Removal
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2015-07-04 07:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (58 votes), past polls