1

我在替换“。”时遇到问题 从一个特定的变量,var a =“test.test 2.5 test”,我的预期结果是“test.test 25 test”所以我想删除'。' 从数字(2.5 到 25)而不是任何字母(test.test 必须保持 test.test)。有什么方法可以在 JavaScript 中做到这一点?

谢谢

4

1 回答 1

2

编辑:更好:

"test.test 2.5 test".replace(/(\d)\.(\d)/, "$1$2");

这有效:

"test.test 2.5 test".replace(/(\d)\.(\d)/, function(a, b, c) { return b + c; });

这替换<digit> <dot> <digit><digit> <digit>.

于 2012-12-28T06:45:06.737 回答