I am trying to match decimal numerals with no digits before the decimal point in a string using regex. For example, I have the strings:
The dimensions of the object-1 is: 1.4 meters wide, .5 meters long, 5.6 meters high
The dimensions of the object-2 is: .8 meters wide, .11 meters long, 0.6 meters high
I want to capture only the decimal numbers without integer digits and prefix leading zeros to them. So my final desired output will be:
The dimensions of the object-1 is: 1.4 meters wide, 0.5 meters long, 5.6 meters high
The dimensions of the object-2 is: 0.8 meters wide, 0.11 meters long, 0.6 meters high
This is what I have tried so far:
(\d+)?\.(\d+)
This expression is capturing all the decimal numbers such as: 1.4, .5, 5.6, .8, .11, 0.6.
But I need to capture only decimal numbers without integer digits: .5, .8, .11.
Use a negative lookbehind:
(?<!\d)(\.\d+)