Imagine a scenario where you have a string containing numbers, such as,
test() test 12,01% test (12,4) 12.3 s 2 some other text, other text, 2,text
Your task is to replace the numbers with decimals instead of commas without altering anything else in the string. Therefore, the string should look like this:
test() test 12.01% test (12.4) 12.3 s 2 some other text, other text, 2,text
You may have attempted a solution like the following:
var newstr = str.replace(/^\d+,\d+$/g, "\1.\2");
or var newstr = str.replace(^\d*\,?\d+$/g, "\1.\2");
- This regex pattern is an attempt to match any number with a comma: ^\d*\,?\d+$