Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
48
rated 0 times [  55] [ 7]  / answers: 1 / hits: 9445  / 10 Years ago, tue, may 20, 2014, 12:00:00

I want to remove commas from numbers in a text, and I have the following:



/du002cd/


But this didnt work, and I'm not sure why (looking for a number, a comma, then a number).
Overall, I want to detect: (number) km, so that I'll convert it to meters. With the help of others, this is what I have for detecting a number (works on decimals):



/b(d+(?:.d+)?)+ *km/gi


Is it easier to modify the above or should I first remove the commas from all numbers?



Many thanks in advance!


More From » regex

 Answers
3

A way to go is to match the parts around the comma and then remove it:



var input = '124,000 km';
input.replace(/(d+),(d+s?km)/g, '$1$2');

[#45191] Monday, May 19, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
stefanicarolinat

Total Points: 145
Total Questions: 91
Total Answers: 93

Location: Cambodia
Member since Thu, Oct 7, 2021
3 Years ago
;