Sublime Forum

Find 2 digit floating point number and appending 0 to the end

#1

Suppose i have the following data:

004-subject01-shashlik-normal_surface-impaired_vision-hold-1,1.6
025-subject01-toy-normal_surface-impaired_vision-hold-1,1.884
026-subject01-cigarette-normal_surface-impaired_vision-hold-2,1.3
029-subject01-toy-normal_surface-impaired_vision-hold-2,1.900

I need to replace 2 digit floating numbers like 1.6 and 1.3 by appending 0 to the end like 1.60 and 1.30. Don’t know how to accomplish this with regex.

Any idea!

Thanks

0 Likes

#2

Replace (\d+\.\d(?!\d)) with \10.

3 Likes

#3

Perfect…
And how will i extend the same pattern to match three digit floating point numbers like 2.13 or 1 digit without any decimal point like 2 to 2.00
For instance i got these numbers:
2.25
2.31
1
1.335
1.155
1.515
1.98
1.605
I got some results with Replace (\d+.\d{2}(?!\d)) with \10
I want to make all of them the same length by adding appending trailing 0 to the end.

0 Likes

#4

I prefer using a replacement of ${1}0, it’s clearer that we are not trying to reference capture group 10 :slight_smile:

1 Like

#5

You might find this educational: https://regex101.com/

I’ve found when I’m trying to puzzle out a complicated regex tools like this check my reasoning. I’ve also found they are useful for learning.

0 Likes