Removing spaces between numbers separated by comma

纵饮孤独 提交于 2021-01-28 06:25:02

问题


I would like to remove any space between numbers separated by "." or ","

for example: 10 , 45, 3 should be: 10,45,3 and 10 . 45 . 3 should be: 10.45.3

Any help to do that in regular expressions ?


回答1:


Using /(\d)\s*([,.])\s*(\d)/g, "$1$2$3" you should be able to do that

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)


来源:https://stackoverflow.com/questions/43154946/removing-spaces-between-numbers-separated-by-comma

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!