I need to change some html tags inside of a document that are marked with a class named highlighted. I need a regex to find inside of this document for tags in this form (<a><span class="highlighted">VAL</span>)
adjacent to similar ones and replace it with part of its content keeping the data inside of span and append it to the others found.
Input
<p>
<a name='hl_1'></a><span id='hl_2_0' class="highlight">word1</span>
<a name='hl_2'></a><span id='hl_3_1' class="highlight">word2</span>
<p>Something in the middle that shouldn't change</p>
<a name='hl_3'></a><span id='hl_4_0' class="highlight">word3</span>
<a name='hl_4'></a><span id='hl_5_1' class="highlight">word4</span>
<a name='hl_5'></a><span id='hl_6_1' class="highlight">word5</span>
</p>
Expected result
<p>
<a name='hl_1'></a><span id='hl_2_0' class="highlight">word1 word2</span>
<p>Something in the middle that shouldn't change</p>
<a name='hl_1'></a><span id='hl_4_0' class="highlight">word3 word4 word5</span>
</p>
I hope you understand my questions. To be honest I'm not really sure I can use Regex to perform this kind of complex operation but a friend suggested it, so that's why I need your help.
Thanks again guys.