Search code examples
regexreplacezeroeditplus

EditPlus Regex - How to replace group 1 followed by 0


I'm trying to replace with Regex's EditPlus, values that contain comma-separated numbers and two decimal points, so they have 3 decimal points, adding a zero to the end. But my attempts eventually delete the value of the group instead of adding the zero to the end. The text is from a csv file, tab separated, over 12000 lines.

The Text to replace (just example):

Car 48,589  27,56   NULL    NULL
Bike    NULL    12,258  NULL    45,896
Bus NULL    11,23   NULL    85,25
Truck   23,45   NULL    45,458  NULL
Boat    45,89   74,12   NULL    NULL

Find Regex String:

(\t[0-9]{2},[0-9]{2})([^0-9]|$)

Replace Regex String attempts:

1. $10$2   // delete String Group 1
2. $1\0$2  // make a copy of group 1 until the end

The Expected result is:

Car 48,589  27,560  NULL    NULL
Bike    NULL    12,258  NULL    45,896
Bus NULL    11,230  NULL    85,250
Truck   23,450  NULL    45,458  NULL
Boat    45,890  74,120  NULL    NULL

Solution

  • The problem is that expression \10 does not mean \1 (the first fount instance) and 0. It means found instance number ten.

    You can do the replacement in two steps: add some placeholder symbols that are not in you file, e.x. @@@@@

    enter image description here

    And in the second step replace the placeholder with 0

    enter image description here

    And the result is:

    enter image description here

    The \2 is needed to correctly work with the numbers at the end of line, like in line number 3.