CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
how do I delete blocks of code

 



clued
stranger

Aug 22, 2001, 9:52 PM

Post #1 of 5 (5373 views)
how do I delete blocks of code Can't Post

Hi everyone,

I need to take this html (or any HTML between specific comment tags)-

//ig;

and just about every combination I can think of.

Can this be done with a regex?
I read the documentation on HTML::Parser, and it may as well have been encrypted for as much as I understood it.

Thanks for help or advice.

Bob



clued
stranger

Aug 22, 2001, 9:54 PM

Post #2 of 5 (5371 views)
Re: how do I delete blocks of code [In reply to] Can't Post

try the code again

Hi everyone,

I need to take this html (or any HTML between specific comment tags)-

//ig;

and just about every combination I can think of.

Can this be done with a regex?
I read the documentation on HTML::Parser, and it may as well have been encrypted for as much as I understood it.

Thanks for help or advice.

Bob



clued
stranger

Aug 22, 2001, 9:58 PM

Post #3 of 5 (5371 views)
Re: how do I delete blocks of code [In reply to] Can't Post

Oh well, it won't show the code or regex examples.

Is there a regex that will delete all code between two specific HTML comment tags?
The code could contain literally any characters, symbols, anything on a keyboard.

Thanks




fashimpaur
User

Aug 23, 2001, 5:45 AM

Post #4 of 5 (5364 views)
Re: how do I delete blocks of code [In reply to] Can't Post

Gee, I saw the reply count was up and almost did not stop to see this post. But, curiosity got the best of me and I wanted to see what your question was. I will use backslashes to try to keep the comments from disappearing in the post.

Here is the example I tested:

my $htmlText = qq~
<h3>Some html</h3>
<h4>Don't know what to show</h4>
this text

is not

to be

displayed

<!-- but here is a comment ending -->
This text should show
~;

# assume $htmlText is read in line by line from file and stuffed
# in array, then Result would be something like:

my @html = split(/\n/, $htmlText);
my @cleanedHtml;
my $hideFlag = 0;

while (@html){
$pattern = "\<\!\-\-(.+?)\-\-\>";
my $line = shift @html;
if ($hideFlag){
$hideFlag = 0 if $line =~ /$pattern/;
next;
}
if (!$hideFlag){
if ($line =~ /$pattern/){
$hideFlag = 1;
next;
}
else {
push @cleanedHtml, $line;
}
}
}

print join "\n", @cleanedHtml;


Will attach .txt file also. After previewing the post, I am afraid I will miss something in the translation.

HTH,

Dennis

$a="c323745335d3221214b364d545a362532582521254c3640504c37292f493759214b3635554c3040606a0",print unpack"u*",pack "h*",$a,"\n\n"


clued
stranger

Aug 23, 2001, 3:30 PM

Post #5 of 5 (5358 views)
Re: how do I delete blocks of code [In reply to] Can't Post

Thank you Dennis, that was pretty much what I needed.
I hadn't thought of that approach, and it works well.

Bob


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives