开发者

Removing double space but not new line

I have used script to remove the double spaces. but this script is removing the new line also along with the space.

Suppose Input is "\s\s\n\n"
Script's output is "\s"
Desired Output "\s\n\n"

That I simply want to remover double space but not new line.
Want to skip new line.

function 开发者_JAVA技巧clean(f) { f.value=f.value.replace(/^\s+|\s+$/g,'').replace(/\s\s+/g,' '); return true; }


You're currently using \s which expunges any whitespace. If you wish to remove double or greater spaces whilst retaining all \n you can use the following:

replace(/ {2,}/g,'')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜