Removing data between two HTML tags?

R

Rob

Hello,

I am trying to use perl to remove all data which comes between these
two tags:

<div class="left">......</div>


This is the code I have so far but it is not doing the job:

$description=~ s|(.*? <div \s+ class="left"> .*? <div \s+
class="left"> .*?)<div \s+ class="left"> .*? </div>(.*? <div \s+
class="left">)|$1$2|sxg;

Any help would be appreciated.

Many thanks

Rob
 
J

James Wright

Hello,

I am trying to use perl to remove all data which comes between these
two tags:

<div class="left">......</div>


This is the code I have so far but it is not doing the job:

$description=~ s|(.*?<div \s+ class="left"> .*?<div \s+
class="left"> .*?)<div \s+ class="left"> .*?</div>(.*?<div \s+
class="left">)|$1$2|sxg;

Any help would be appreciated.

Many thanks

Rob

Use an HTML parser.
 
C

ccc31807

My bitter experience tells me that only pain lies along this road you
are taking.

Still, it's instructive to make the attempt. A long time ago I
attempted to do something like this by building an RE incrementally,
piece by piece. I failed, but the lessons I learned have stood me in
very good stead, and several times a month I build complex REs the
same way. And guess what? I don't fail!

I'm not saying that the OP should reinvent the wheel, but that the OP
needs to go through the process of reinventing the wheel so he can
understand how the original wheel inventors did it, and then he can
use that knowledge to invent something useful on his own.

CC.
 
R

Rob

<969eb4b1-46d4-4ce4-b960-b1abd2563...@f30g2000yqa.googlegroups.com>,

Thank you all for your help and suggestions. I have achieved what I
wanted by just creating HTML comments around the text to remove and
removing that instead, as follows:

$data =~ s/<!-- start-top -->.+?<!-- end-top -->//smg;

The article at http://tinyurl.com/64uvzgp set me on the right track.

Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top