标签: javascript regex replace whitespace
可能重复: Remove all multiple spaces in Javascript and replace with single space
如何替换,例如:
" " " " " " " "
与
" "
如何使用正则表达式将所有空白字符替换为单个空字符?
答案 0 :(得分:5)
我认为myString.replace(/ {2,}/g," ")应该这样做。
myString.replace(/ {2,}/g," ")