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
In reply to Clarification on greediness by prasadbabu
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |