1

Possible Duplicate:
Remove all multiple spaces in Javascript and replace with single space

How can I replace, for instance this:

"  "
"   "
"    "
"     "

with

" "

How can I replace all the empty space characters with a single empty char using regex?

0

1 Answer 1

6

I think myString.replace(/ {2,}/g," ") should do it.

Sign up to request clarification or add additional context in comments.

1 Comment

Better use / {2,}/g, or you'll also replace all the single spaces with themselves.