Search code examples
regexnotepad++

Remove the spaces before ; and after ; without removing the new line


I'm using Notepad++ v8.4.6.

I want to replace all the spaces after and before ;. For example, given this line:

H;53; ;00 00 35.37;-29 15 48.2;10.96; ;H;000.14739023;-2.926.338.247; ; -1.76; 11.94; -12.96; 2.18; 1.03; 2.45; 3.15; 1.27; 0.03;-0.07; 0.07; 0.27; 0.05; 0.08;-0.10;-0.32; 0.11;-0.22;0; 1.19;53; ; ; ; ; ; ; ; ; ; ;T; ;111.006;0.0041;0.041;152; ;11.03;11.17; ; ; ; ; ; ; ;1; ; ; ; ; ; ; ; ; ; ;G; ; ; ;C-29 18916; ;0.72; ;

I want to get this:

H;53;;00 00 35.37;-29 15 48.2;10.96;;H;000.14739023;-2.926.338.247;;-1.76;11.94;-12.96;2.18;1.03;2.45;3.15;  1.27; 0.03;-0.07; 0.07; 0.27; 0.05; 0.08;-0.10;-0.32; 0.11;-0.22;0; 1.19;53;;;;;;;;;;;T;;111.006;0.0041;0.041;152; ;11.03;11.17;;;;;;;;1;;;;;;;;;;;G;;;;C-29 18916;;0.72;;

On my previous question Remove all the spaces between `;` and `CRLF`, I got how to remove that spaces.

Now I have tried this to remove the space after ;, but it also remove the new line at the end of the line:

enter image description here

If I have this:

; C-29 18916 ;

I want to get this:

;C-29 18916;

WITHOUT REMOVING THE NEW LINE CHARACTER.

How can I do that without removing the new line there is something like this ;\n?


Solution

  • To replace all spaces before and after ;, match on *; *

    • * - (a space followed by *) matches on zero or more spaces
    • ; - a literal ;
    • * - zero or more spaces

    and substitute with ;.

    Demo