<p>I would like such empty span tags (filled with <code>&amp;nbsp;</code> and space) to be removed:</p>

<p><code>&lt;span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;</code></p>

<p>I've tried with this regex, but it needs adjusting: </p>

<p><code>(&lt;span&gt;(&amp;nbsp;|\s)*&lt;/span&gt;)</code></p>

<p><code>preg_replace('#&lt;span&gt;(&amp;nbsp;|\s)*&lt;/span&gt;#si','&lt;\\1&gt;',$encoded);</code></p>

.
```
```
qr{<span[^>]*(/>|>\s*?</span>)}
```
```
Should get the gist of them. ( Including XML style-self closing tags ie:  )
But you
really
shouldn't use regex for HTML processing.
Answer only relevant to the context of the question that was visible before the formatting errors were corrected