I am attempting to correct a grammar error from an API. I'm attempting to replace 70,2bn to 70.2bn I've went about it to just simply to .replace(/,[0-9]bn/g, '.') but this ends up removing the last number after the comma.
Here is an example of the full string "The average population is 492,213 and revenue generated is 70,2bn"
With the current .replace(/,[0-9]bn/g, '.') it is replacing the comma with a period which I am expecting, but how can I return back the number that is cut off?
This number 70,2bn is different per page, so I attempting to find a solution that will work for different scenarios that include bn such as 2,1bn, 100,3bn etc.
Here is a code snippet:
let string = "The average population is 492,213 and revenue generated is 70,2bn"
console.log(string)
string = string.replace(/,[0-9]bn/g, '.bn')
console.log(string)
I am expecting an outcome of "The average population is 492,213 and revenue generated is 70.2bn"
string.replace(/,([0-9]bn)/g, '.$1')