<p>I have the following string:</p>

<pre><code>&lt;SEM&gt;electric&lt;/SEM&gt; cu &lt;SEM&gt;hello&lt;/SEM&gt; rent &lt;SEM&gt;is&lt;I&gt;love&lt;/I&gt;, &lt;PARTITION /&gt;mind
</code></pre>

<p>I want to find the last "SEM" start tag before the "PARTITION" tag. not the SEM end tag but the start tag. The result should be:</p>

<pre><code>&lt;SEM&gt;is &lt;Im&gt;love&lt;/Im&gt;, &lt;PARTITION /&gt;
</code></pre>

<p>I have tried this regular expression:</p>

<pre><code>&lt;SEM&gt;[^&lt;]*&lt;PARTITION[ ]/&gt;
</code></pre>

<p>but it only works if the final "SEM" and "PARTITION" tags do not have any other tag between them. Any ideas?</p>

Have you tried this:
```
```
<EM>.*<PARTITION\s*/>
```
```
Your regular expression was matching anything but "<" after the "EM" tag. Therefore it would stop matching when it hit the closing "EM" tag.