Given that you also want to cover tabs, newlines, etc, just replace \s\s+
with ' '
:
(假设您还想覆盖制表符,换行符等,只需将\s\s+
替换为' '
:)
string = string.replace(/ss+/g, ' ');
If you really want to cover only spaces (and thus not tabs, newlines, etc), do so:
(如果您真的只想覆盖空格(而不是制表符,换行符等),请这样做:)
string = string.replace(/ +/g, ' ');
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…