我想删除数字之间用“。”分隔的任何空格。要么 ”,”
例如:10,45,3应该是:10,45,3
和10。 45。 3应为:10.45.3
对正则表达式有帮助吗?
最佳答案
使用/(\d)\s*([,.])\s*(\d)/g, "$1$2$3"
您应该能够做到这一点
var str = "Operations and maintenance $258 .277 billion , Military Personnel $153 .531 billion ,Procurement $97, 757 billion. Research, Development, Testing & Evaluation $63 . 347 billion, Military Construction $8 , 069 billion Family Housing $1. 483 billion.";
str = str.replace(/(\d)\s*([,.])\s*(\d)/g, "$1$2$3");
console.log(str)