Let's say I have the following text: (example)
<table>
<tr>
<td>
<span>col1</span>
</td>
<td>col2</td>
</tr>
<tr>
<td>text1</td>
<td>
<span>text2</span>
</td>
</tr>
</table>
I want to replace all <span>%</span>
by %
, and I've come up with a solution like this:
replace(/<span>(.*)<\/span>/gi, function(full, text){return text;})
It replaces from the first span
until the last one by only one occurrence, therefore the whole structure of my table is messed up.
How could I tell JS to replace each occurrence by the right one and not everything at once? The solution needs to be in Javascript obviously. I hope my example is not too "simple" and bugged to avoid any confusion.