You seem to be dealing with currency strings. You may follow your blacklist approach and use .replace(/[,\s$]+/g,"") to remove all occurrences of 1+ commas, whitespaces and dollar symbols. However, once you have a pound, euro, yen, etc. currency symbol, you will have to update the regex.
Using a whitelisting approach is easier, remove all chars that are not on your whitelist, digits and dots:
.replace(/[^0-9.]+/g,"")
See the regex demo.
The [^0-9.]+ matches 1 or more occurrences of any chars other than (the [^...] is a negated character class that matches the inverse character ranges/sets) digits and a dot.
JS demo:
var nums = ["34 345 324.34 $", "$34,345,324.34"];
var rx = /[^0-9.]+/g;
for (var s of nums) {
console.log(s, "=>", s.replace(rx, ""));
}
replace(/[$,\s]/g,"").replace(/[$,\s]+/g, "");num2.replace(/[^\d.]/g, '')