开发者

Removing double space but not new line

开发者 https://www.devze.com 2023-02-19 16:52 出处:网络
I have used script to remove the double spaces. but this script is removing the new line also along with the space.

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

精彩评论

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

关注公众号