Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Perl Command Line Regex

by rminner (Chaplain)
on Nov 12, 2006 at 21:46 UTC ( [id://583601]=note: print w/replies, xml ) Need Help??


in reply to Perl Command Line Regex

Hi,
Fletch is right, that it's usually not a good idea to do SGML/HTML/XML parsing using perl regex. But in case you really want to do it, the following snippet will remove the two tags, and the text in between.
#!/usr/bin/perl use strict; use warnings; my $string = <<EOFDATA; whatever <!-- REMOVESTART --> test test test <!-- REMOVEEND --> you are trying to do EOFDATA my $start_tag = quotemeta('<!-- REMOVESTART -->'); my $end_tag = quotemeta('<!-- REMOVEEND -->'); $string =~ s{$start_tag.*?$end_tag\n*}{}gms; print $string;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-19 03:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found