【发布时间】:2021-03-24 21:25:26
【问题描述】:
这是我的代码。它仍然返回null,我不知道为什么!
var tName = "18.56x^2 - 5.45x -3.78";
abc = tName.replace(/x/g, "").replace("^2", "").replace(/\s/g, "");
console.log(abc);
$re = "/-?\\d+(?:\\.\\d+)?/m";
$str = abc.toString();
console.log($str.match($re));
【问题讨论】:
-
只是提示您可以使用
https://regex101.com/来调试您的正则表达式 -
另外
$str = abc.toString();是不必要的
标签: javascript arrays string numbers floating