RegEx如何用一个空格替换多个空格

时间:2011-08-08 14:55:57

标签: javascript regex replace whitespace

  

可能重复:
  Remove all multiple spaces in Javascript and replace with single space

如何替换,例如:

"  "
"   "
"    "
"     "

" "

如何使用正则表达式将所有空白字符替换为单个空字符?

1 个答案:

答案 0 :(得分:5)

我认为myString.replace(/ {2,}/g," ")应该这样做。