如何在java String中的空格周围包装"<pre>"标签?

sma*_*ufo 1 java regex

假设我有一个很长的java字符串,我需要用<pre></pre>标签包装所有空格(长度> = 2)...,如何实现?

例如:

before :
String str = "<font color=\"#000000\">A B  C   D</font>"

after :
<font color=\"#000000\">A B<pre>  </pre>C<pre>   </pre>D</font>

Between A and B is one whitespace , and not wrapped.
Between B and C is two whitespaces , and it is wrapped.
Between C and D is three whitespaces , and it is wrapped,too.
Run Code Online (Sandbox Code Playgroud)

如何在RegExp中实现这一目标?非常感谢 !

Gum*_*mbo 5

如何使用CSS解决方案white-space:

white-space: pre
Run Code Online (Sandbox Code Playgroud)

这个白色空间序列不会崩溃.所以:

<font color="#000000" style="white-space:pre">A B  C   D</font>
Run Code Online (Sandbox Code Playgroud)