Unable to replace spaces, newlines, tabs, etc.

  • Let me start with an example:

    Say I have the following text:

    More Text

    and I have a lot of it like that, but I want to change all of it to look like:

    Text More Text

    So, all I want to do is search for the \n and two spaces that are preceding the “More Text” and replace it with a tab between the “Text” and “More Text”. Well, I distinctly remember being able to do this in the past but lately it seems that it isn’t possible. The only thing I have checked is the Extended search option, nothing else. Here is a screenshot of what I am talking about: https://i.imgur.com/n2si7G0.png

    When I select anything that isn’t actual text, what should be formatting, it seems that Windows is unable of selecting and copying that information separately. This might be a Windows quirk, but is there any way this can be fixed for Notepad++? I have noticed this is true for pretty much every text editor I use in Windows.

  • @Polorboy

    Hard to say with 100% certainty, but it appears like you are searching for a Unix line ending followed by one or more spaces (looks like more than one). Your sample text doesn’t show any spaces following the line ending, but I suppose the markdown syntax used on this site could be consuming it… Like I said, too hard to tell, too many questionables…

  • As Scott said, it’s hard to tell, because the forum ate your whitespace (and we cannot see your EOL characters in a paste).

    I did an example: turn on View > Show Symbol > Show all characters to show the different results and make sure spaces, tabs, and EOL were all visible:

    On the left, I marked \n (LF SPACE SPACE) {top left}, and then replaced it with tab {bot left}. As you can see, it found two LF that were followed by two spaces – one in the WINDOWS EOL (CRLF) section, and one in the LINUX EOL (LF) section. But when it does the replace, it leaves the CR in the WINDOWS EOL section, which Notepad++ properly renders as a newline sequence for line purposes.

    On the right, I marked \r\n (CR LF SPACE SPACE) { top right }, and then replaced it with tab {bot right}. As you can see, it only found the one in the WINDOWS EOL section, but properly replaced the full EOL sequence, rather than just the LF portion of the CR LF.

    So, if your file has linux line endings, then your regex should have worked for your described data. If you file has windows line endings, then your regex only replaces part of the EOL, and you should use \r\n (CR LF SPACE SPACE) instead.

    If you switch to regular expression mode, then the magical \R is enabled: this magical regex sequence matches CR, LF, or CR LF. So search = \R (backslash big-R space space) and replace with \t would work for either style of line ending.

Log in to reply