regex replace doesn't work
-
Hi together,
I’m struggling with regex search and replace and need some help.
I got a huge linux log file wich is looking like this:
2020-01-01_00:02:13 MQTT2_DVES_834483 ENERGY_Power: 0 2020-01-01_00:02:13 MQTT2_DVES_834483 ENERGY_Voltage: 268 2020-01-01_00:02:13 MQTT2_DVES_834483 Time: 2020-01-01T01:02:12 2020-01-01_00:02:13 MQTT2_DVES_834483 ENERGY_ApparentPower: 0 2020-01-01_00:02:13 MQTT2_DVES_834483 ENERGY_Today: 0.000 2020-01-01_00:02:13 MQTT2_DVES_834483 ENERGY_Current: 0.000 2020-01-01_00:02:13 MQTT2_DVES_834483 ENERGY_ReactivePower: 0 2020-01-01_00:02:13 MQTT2_DVES_834483 ENERGY_Factor: 0.00 2020-01-01_00:02:13 MQTT2_DVES_834483 ENERGY_Period: 0
I just want to replace the underscore “_” by a space " " between date and time.
The regex search expression
(?<=\d)_(?=\d)
is working well.
But replace doesn’t work at all, if I hit the “Replace” button, the cursor just jumps to the next match.
Typing just a space, or text, or regex again like \s in the replace field doesn’t work.Replacing without regex, check on “Normal”, is working as expected but doesn’t help here.
Any hint is highly appreciated as the supposed workaround by selecting the column with the underscore and try to replace by the coulmn menu (Alt+C) leads to a frozen Notepad++.
best regards
Stef -
If you do a Replace All after ticking Wrap around yours should work just fine.
But perhaps you really do what to see the replacements one at a time? In that event, I suggest you change your search to look for
(\d)_(\d)
and replace it with${1}\x20${2}
The reason yours doesn’t work on a one-by-one basis has to do with an oddity about where Notepad++ starts looking for matches with leading assertions (which you have). If you want more detail on that, just say so.
-
Hi Alan,
thanks a lot, both suggestion are working fine (I never tried to click on “replace all” because I thougt the expression is not workineg…).
By “leading assertions” you are talking about the “look ahead/behind” structure?
Best regards
Stef -
@Stefan-N said in regex replace doesn't work:
By “leading assertions” you are talking about the “look ahead/behind” structure?
Yes.
When you are doing “step finds” (where you press Find Next to repeatedly jump to the next match), the buffer to be searched literally starts right where the caret is.
There is no knowledge of what comes to the “left” of the caret.
Thus, a positive look-behind assertion at that point will always fail – which is what you are seeing.
A negative look-behind assertion will always succeed.
Just a peculiarity of the N++ searching engine.
Something to remember for the future!