Regex match for XML Query Paths?
<p>I have the following paths:</p>

<pre><code>/A      
/A/B        
/A/B/C      
/A/D        
/A/D/E      
/A/D/E/F        
/A/D/E/F/H      
/A/D/E/G        
/A/D/E/G/I      
/A/D/E/F/J      
/A/D/E/G/D
</code></pre>

<p>I want to apply a regular expression to get the matched paths.</p>

<p>I have tried the following regex <code>^/A/(.*)/D$</code> and it gives only the last path which is <code>/A/D/E/G/D</code>. What i want is a regex to get the fourth path and the last path.</p>

<p>The expected output is:</p>

<pre><code>/A/D    
/A/D/E/G/D
</code></pre>