Zuhair Ali
Zuhair Ali

Reputation: 627

Removing spaces between numbers separated by comma

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 ?

Upvotes: 1

Views: 400

Answers (1)

Asons
Asons

Reputation: 87191

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)

Upvotes: 1

Related Questions