从变量中删除除句点以外的所有字母?

Remove all letters from a variable except the period?

我正在做一些网络抓取并试图过滤这个变量。

var oldtext = [=10=].00Amount

var newtext= text.replace(/\D/g, "");

结果为“000”,我需要保留句号。

我知道我可以为每个 $、A、M、O、U、N、T 编写一个替换函数,但是有更聪明的方法吗?

console.log("Price is 1.223$".replace(/[^\d.]/g, ""))

它也包括负值。

console.log("Price is 1.223$".replace(/[^\d.-]/g, ''));