我有这个通常有很多空格的 HTML 字符串
例子:
<p>All these words <br />
<strong>All</strong> <em>these</em> words
<pre> All these words</pre>
</p>
我需要使用 JavaScript 删除它们,并提出了这个正则表达式:
String.replace(/ {2,}/g, '');
这似乎可以替换不需要的空格,但我想保留 PRE 元素内的空格。
这可以用正则表达式吗?