Regular expression for removing whitespaces

前端 未结 6 1568
悲&欢浪女
悲&欢浪女 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 09:56

    Try this:

    str.replace(/\s+/g, ' ').trim()
    

    If you don't have trim add this.

    Trim string in JavaScript?

提交回复
热议问题