Regular expression for removing whitespaces

前端 未结 6 1569
悲&欢浪女
悲&欢浪女 2020-12-29 09:12

I have some text which looks like this -

\"    tushar is a good      boy     \"

Using javascript I want to remove all the extra white spac

6条回答
  •  遥遥无期
    2020-12-29 10:06

    This can be done in a single String#replace call:

    var repl = str.replace(/^\s+|\s+$|\s+(?=\s)/g, "");
    
    // gives: "tushar is a good boy"
    

提交回复
热议问题