I have below xml string. i want to use js Regex to query the closest '<and>
' and replace it with something.
<Query><Where><And><In><FieldRef Name='Title' /><Value Type='Text'>kk</Value></In><And><In><FieldRef Name='DocIcon' /><Value Type='Computed'>bb</Value></In><And><In><FieldRef Name='Continent' /><Value Type='Choice'>Europe</Value></In><Eq><FieldRef Name='Constituency' /><Value Type='Choice'>Jordan</Value></Eq></And></And></And></Where></Query>
Formatted:
<Query>
<Where>
<And>
<In>
<FieldRef Name='Title' />
<Value Type='Text'>kk</Value>
</In>
<And>
<In>
<FieldRef Name='DocIcon' />
<Value Type='Computed'>bb</Value>
</In>
<And>
<In>
<FieldRef Name='Continent' />
<Value Type='Choice'>Europe</Value>
</In>
<Eq>
<FieldRef Name='Constituency' />
<Value Type='Choice'>Jordan</Value>
</Eq>
</And>
</And>
</And>
</Where>
</Query>
<Eq><FieldRef Name="Constituency" /><Value Type="Choice">Jordan</Value></Eq>
is a fixed string, other parts are not. which means there maybe many <and> <In>
. How to get the closet <and>
?
I tried below regex but fail:
/(<And>)<In>.*<\/In>(<Eq><FieldRef Name="Constituency" \/><Value Type="Choice">Jordan<\/Value><\/Eq>)<\/And>/gi