Replacing something that is not a number is a bit more complicated than replacing what is a number.
Those who propose simply adding a point ignore the fact that. also used as a period, therefore:
This is a test. 0.9, 1, 2, 3 This is a test. 0.9, 1, 2, 3 will become .0.9123 .
The specific regex in your problem will depend on the goal. If your line has only one number, you can do this:
var.replace(/.*?(([0-9]*\.)?[0-9]+).*/g, "$1")
This finds the first number and replaces the entire string with the matched number.
Jeff B Mar. 31 '10 at 17:36 2010-03-31 17:36
source share