How about this:

<cfset newString = rereplaceNoCase(oldString,"<([^>]*)>[^<]*</\1>","",
all")>

What it doesn't cope with are nested tags. You could write: 

<cfset newString = rereplaceNoCase(oldString,"<([^>]*)>.*</\1>","", all")>

but that would match from the first of a given tag to the last.

If you're using cfmx you can write:

<cfset newString = rereplaceNoCase(oldString,"<([^>]*)>.*?</\1>","", all")>

to give you minimal matching which should be just what you want.

Matt.

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:bounce-cfaussie-
> [EMAIL PROTECTED] On Behalf Of Kay Smoljak
> Sent: Monday, 10 November 2003 11:47 a.m.
> To: CFAussie Mailing List
> Subject: [cfaussie] regex to remove tags and text between them
> 
> I used to have a Perl guru in the office who would fix all my regex probs,
> but alas no more.
> 
> Given a string with some html text in it, I need to remove both the tags
> and the text within them. Eg, given "ColdFusion
> Rules!<small>(ahem)</small>" I want to
> return "ColdFusion Rules!". I can remove the tags easily:
> 
> <cfset newString = rereplace(oldString,"<[^>]*(>|$)","")>
> <cfset newString = rereplace(oldString,"</?[^>]*(>|$)","")>
> 
> but I don't know how to also remove anything found between two sets of
> tags. I've been messing around with list functions, trying to use
> ListContains where '<small>' and '</small>' are the delimiters, but I
> figure there must
> be an easier way that handles *any* tag using regex.
> 
> Any help greatly appreciated!
> K.
> 
> ---
> You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
> To unsubscribe send a blank email to leave-cfaussie-
> [EMAIL PROTECTED]
> 
> MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia
> http://www.mxdu.com/ + 24-25 February, 2004




---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]

MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia
http://www.mxdu.com/ + 24-25 February, 2004

Reply via email to