I did a program once that only allowed certain tags and then removed all
others.  It seems easiest to permit the tags you want, and remove all
others, so for your needs, I think the following will suffice:

        $allowed_tags = "TYPE|DESCRIPTION";
        s/<(?!$allowed_tags).*?>//gis;

I gave this a brief test, and it appears to work.  This also makes it easy
to manage as you change permitted tags in the future.

Whatever you do, you will need to find a way to specify either tags you will
permit, or tags you will deny.  I would figure out which is easier to
specify (probably the ones you'll permit, from the looks of things), and
work your regexp around that.  Of course, as has been suggested by another,
you could look at HTML::Parse, but I'm not really sure what you'll find
there.

Chad Uretsky
Lead Network and Security Engineer
NetIQ Corporation
[EMAIL PROTECTED]
Direct: 713-418-5200
www.netiq.com
 
 
 


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Craig
Cardimon
Sent: Thursday, February 24, 2005 8:02 AM
To: ActivePerl
Subject: Best way to selectively strip HTML tags


I need to strip HTML-style "<" and ">" tags and their contents from 
ASCII text while not disturbing customized tags that might say <TYPE> or 
<DESCRIPTION>. Is there a way to do this without going bonkers?

I'm using

***

s/<(?:[^>'"]*|(['"]).*?\1)*>//gs;

***

to strip all angle braces from the text. It works like gangbusters, but 
I've discovered it works a little too well.

Now I need something I can apply more judiciously. Any hints, tips, or 
suggestions would be appreciated.

-- 

Craig Cardimon


---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 0508-2, 02/23/2005
Tested on: 2/24/2005 9:01:33 AM
avast! - copyright (c) 1988-2004 ALWIL Software. http://www.avast.com



_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to