Search code examples
regexnotepad++

How to substitute substring with dynamic number of spaces


I would like to use Notepad++ to substitute the decimal digits of a column of numbers with an equivalent amount of white spaces.

For example, this input (vertical bars are there on purpose)

|    1.23|
|  45.678|
|901.2345|

would become

|    1   |
|  45    |
|901     |

Basically, the dot and decimal digits have been substituted with a dynamic number of white spaces: 2+1 spaces for the first row, 3+1 for the second, 4+1 for the third.

I've looked at a few different posts like this and have tried something like: replace \.\d+ with \s+, without success.


Solution

  • Try this in notepad++ if I have understanded you well,

    Find: ^([ |\d]*)\.|\G\d{1,1}
    Replace with: $1 after $1 there is a single space

    Now it is possible with Notepad++
    Updated answer

    There is a prove with image
    enter image description here