I have a xml file in following format
<starttag name="AAA" >
<innertag name="XXX" value="XXX"/>
<innertag name="XXX" value="XXX"/>
<innertag name="XXX" value="YYY"/>
</starttag>
<starttag name="BBB" >
<innertag name="XXX" value="XXX"/>
<innertag name="XXX" value="XXX"/>
<innertag name="XXX" value="XXX"/>
</starttag>
<starttag name="CCC" >
<innertag name="XXX" value="XXX"/>
<innertag name="XXX" value="XXX"/>
<innertag name="XXX" value="YYY"/>
</starttag>
..
..
..
I want to extract all those name attributes of starttag whose any of the innertag has value YYY.
So in the file above, the output will be AAA and CCC. I can only use regex matching. I suppose it is possible using lookaheads but not able to create regex patterns for multilines. I know how to use regex for single line and I tried using same with this also but not getting expected outputs. Anyone any headway on this.
Edit: Though I have put xml example but actually I am trying to get to know multiline regex matching and I am trying on this file which I am failing. Please avoid XML parsing related solutions.
Update: As per Steven suggestion, following worked
pcregrep -M '<starttag name="([^"])*"[^>]*>(\s|<innertag[^>]*>)*<innertag name="[^"]*" value="YYY"\/>(\s|<innertag[^>]*>)*<\/starttag>' file.xml
grep -Pzo '<starttag name="([^"])*"[^>]*>(\s|<innertag[^>]*>)*<innertag name="[^"]*" value="YYY"\/>(\s|<innertag[^>]*>)*<\/starttag>' file.xml