Search code examples
regextext-editoreditplus

Replacing comma by dot only in numbers in a texteditor using search and replace function


i got a table as txt.file with all the variables beeing seperated by ;.

Lets say i got 3 Variables: ID, Size and Comment.

My Data could look something like this:

1;1.5;hello. how are you?  
2;2.5;a comment.  
3;2.1;another comment.

Now i would like to replace the comma-sign from dot to comma.
If i use the standard search and replace function in my text-editor it will change all . to , without any problem. But i want to change only those . to , which are surrounded by numbers left side and right side.
1.5 should be changed to 1,5 but hello. how are you? should not be changed to hello, how are you?

I found a regular expression for searching only dots surroundet by numbers:

[0-9][\\.][0-9] 

Now i would like to replace those surroundet dots, but unfortunately it doesn't work yet. When replacing [0-9][\\.][0-9] by ,, 1.5 is changed to , only instead of 1,5.

Is there any nice way to use search and replace from a texteditor to solve this problem?

Thanks in advance!


Solution

  • EditPlus does not support lookbehinds, so you need to use groups.

    (\d)\.(\d)
    

    Substitution: \1,\2

    • () Capturing group
    • \d matches a digit (equal to [0-9])
    • \1 \2 Capturing group 1. and group 2.

    enter image description here