Improve regexp in replaceSpace function