I have this segment of xml.
<condition name="gender" value="male">
<condition name="somethingelse" value="somevalue">Target string</condition>
</condition>
You can see that these are nested.
What I need to do is get the middle condition containing the 'target string'.
People will probably suggest to use an xml parser or something, but I want to do it with regex.
I messed around with a regex but I just do not know them well enough yet.
Take this for example.
$regex = '<condition name="[a-z0-9]+" value="[a-z0-9]+">([^<>].*?)<\/condition>';
preg_match_all ( '/' . $regex . '/i', $haystack, $stuff );
What I was trying to do there was match the tags but ignore anything that contains < or > thus avoiding anything that does not contain text.
My example does not work, it's just to show where I got to and now I am stuck.
All it does is give this match, so I am part way there :
<condition name="gender" value="male"> <condition name="somethingelse" value="somevalue">Target string</condition>
Could anyone help please ?