0

I have an html page with multiple <span class="classa"> but I need to remove only the ones that have an opening {, zero or more characters and then a closing } like in the example below:

<span class="classa">
<span class="classb">{</span>
<a href="some link" title="some title">some text</a>
<span class="classb">}</span>
</span>

For example if I have something like this:

<span class="classa">
<span class="classb">{</span>
<a href="some link" title="some title">some text</a>
<span class="classb">}</span>
</span>

then the entire <span class="classa"> and it's children should be removed but if I have this:

<span class="classa">
something here
<span class="classb">{</span>
or something here
<a href="some link" title="some title">some text</a>
<span class="classb">}</span>
or something here
</span>

then nothing should be touched.

How do I do this ? should I write a regex ?

  • 2
    ‘*should I write a regex ?*’ [No.](http://stackoverflow.com/a/1732454/418066) That is to say, don't use regex for the HTML parsing, but you could use it to match the contents. – Biffen Mar 20 '15 at 10:47
  • if you have control over the generated html code why not use "classb open" and "class close" to know for sure the range of the elements which you want to remove? – micnic Mar 27 '15 at 09:25
  • @micnic unfortunately the html code is generated elsewhere –  Mar 27 '15 at 09:29
  • please provide a jsfiddle with the two cases inside and I will try to help you – micnic Mar 27 '15 at 09:45

0 Answers0