On 11/14/06, mira mira <[EMAIL PROTECTED]> wrote:
> hi
>
> I have problem in writing Regex.
>
> This is my sample xml code
> **************************
> <Book>
> <Emphasis type="Bold">
> sample text
>    <Emphasis type="Italic">
>     sample Text
>          <Emphasis type="underline">
>              sample text
>          </Emphasis>
>    </Emphasis>
> sample text
> </Emphasis>
> </Book>
>
> I need to write regex for replacing the Emphasis tags.
> that is i need to replace the following tags:
> <Emphasis type="Bold"></Emphasis> with <B></B>
> <Emphasis type="Italic"></Emphasis> with<I></I>
> <Emphasis type="underline"></Emphasis>with<U></U>
>
> Can anyone help me in writing the match in Regex so that
> the tags are nested properly.
>
> I may have N number of emphasis tags nested in any combination.
>
> I will be very thankful if someone could help me.I'm trying this
> for the past one week.

What you're asking for isn't as easy as it sounds and it's not a one
step process.  You have to find your start tag and then iterate until
you find the proper end tag (i.e. increment a value for each open tag
and decrement for each close tag.  When you find a matching close tag
and your value is 0 then you have the proper close tag.).

It can be done, I'm just saying its not easy.  I've done such a thing
in JS and ColdFusion, but no longer have access to the code (nor did I
own it to begin with since it was written for an employer).  If no one
else has anything handy, I'll try to put something together for you.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: http://www.houseoffusion.com/groups/RegEx/message.cfm/messageid:985
Subscription: http://www.houseoffusion.com/groups/RegEx/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.21

Reply via email to