Advertisement

12.21.2007 at 06:06AM PST, ID: 23038120
[x]
Attachment Details

Removing nested paragraph tags

Asked by NorCal2612 in Perl Programming Language

Tags: regex

I'm trying to remove any nested paragraph tags from a huge file. I have come up with the following regex so far...

s/<paragraph>(.*?)<paragraph>(.*?)<\/paragraph>(.*?)<\/paragraph>/<paragraph>$1$2$3<\/paragraph>/ig;

This appears to work in many cases however it also removes every other pair of properly formatted paragraph tags...

e.g.

If the input was the following:

<paragraph>some data</paragraph><paragraph>more data</paragraph><paragraph>even more data</paragraph>

The regex would result in this being changed to:

<paragraph>some data</paragraph>more data<paragraph>even more data</paragraph>

After thinking about it, it makes sense since I am trying to match to four tag units within the text and the (.*?) doesn't exclude other paragraph tags from being included...

Is there anyway to exclude <paragraph> from the (.*?) match?

Thanks...

TomStart Free Trial
[+][-]12.21.2007 at 06:35AM PST, ID: 20513702

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.21.2007 at 06:42AM PST, ID: 20513751

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.21.2007 at 07:00AM PST, ID: 20513895

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Tags: regex
Sign Up Now!
Solution Provided By: ozo
Participating Experts: 1
Solution Grade: A
 
 
[+][-]12.21.2007 at 07:13AM PST, ID: 20514013

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628