prasadbabu has asked for the wisdom of the Perl Monks concerning the following question:
Hi monks
I need some clarifications in greediness.
The input file has the following text:
<pages> <contentmodel> <level>5</level> <first>35</first> <content>some text</content> </contentmodel> <contentmodel> <level>4</level> <first>45</first> <content>some text</content> </contentmodel> <contentmodel> <level>3</level> <first>25</first> <content>maps</content> </contentmodel> <contentmodel> <level>2</level> <first>15</first> <content>some text</content> </contentmodel> </pages>
In the above input file i want to fetch the <first>\d+</first> tag in the content model in which the content tag has the text 'maps'.
I tried with the following code using zero width assertions. But it is not matching the minimum match. It is matching from the begining of the <first> tag.
(@arr) = $str =~ /(<first>((?!<first>).*?))<content>maps<\/content>/gsi;I dont know where i am going wrong.
The output i need is:
<first>25</first>Thanks in advance
Prasad
janitored by ybiC: Retitle from "greediness" because onewordnodetitles hinder site search
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Clarification on greediness
by zejames (Hermit) on Nov 25, 2004 at 12:41 UTC | |
by thinker (Parson) on Nov 25, 2004 at 14:03 UTC | |
Re: Clarification on greediness
by rinceWind (Monsignor) on Nov 25, 2004 at 12:50 UTC | |
Re: Clarification on greediness
by gopalr (Priest) on Nov 25, 2004 at 12:45 UTC | |
Re: Clarification on greediness
by fglock (Vicar) on Nov 25, 2004 at 12:48 UTC | |
Re: Clarification on greediness
by ikegami (Patriarch) on Nov 25, 2004 at 19:26 UTC |