How to search and replace special characters?

  • cyberman


    I would like to know how can I search and replace special charaters CR/LF(Carriage Return, 0x0D; Line Feed, 0x0A) with regular expression.  For example, I would like to search for two CR/LF and replace with a single CR/LF, i.e. to delete all empty lines.

    Please help!!!

    Thank you very much for your assistance.

    • TextFX has a tool to delete surplus empty lines. It also has a Find & Replace dialog that allows multiline input. Please see the NPPTextFX announcement thread in the plugins forum. (Sourceforge links are all broken).

      • Hi everyone,

        These posts have been really useful although I am wondering if you can find and replace text using wild cards ?


        • pshute

          You can use regular expressions for that.  See for details.

          • how can i replace Null Values that a apear with another char?

    • cyberman

      Thank you very much for replying to my post!!!
      I am a newbie. Would you please explain step by step how to do the job with the function of Find &amp?

    • Don't take literally the improper display of the Sourceforge forums. Find amp-amp-amp; Replace is a Sourceforge mistake, not mine. To read Sourceforge you need to learn HTML so you can translate & back to ampersand.

      As has been posted many times, \r\n support is insufficient to perform your change with the built-in Notepad++ Ctrl+F and Ctrl+H dialogs.

      The TextFX plugin includes a new Find and Replace dialog accessible with Ctrl+R or found in the TextFX-Quick menu that will easily perform your change. Given that a new version of Notepad++ is coming soon and that there is no indication that the new messages I need to support modeless dialog boxes for plugins have been added, you may want to wait until after the new version appears and I can make the source code change to support modeless dialog boxes for plugins.

      The TextFX Find and Replace code is all brand new so download and experiment if you want but I think you'll find that marking your entire document and Plugins - TextFX Edit - Delete blank lines will be easier since you probably already have that and I suspect you'll skip or fail to understand the install instructions in the NPPTextFX announcement thread. As people verify that my find and replace really works, I will probably remove Delete ... Blank Lines from TextFX.

      If you get my multi-line find and replace fully working, you'll put two invisible returns (Ctrl+M) in the Find box and one return in the Replace box; [x]Recurse Replace, [ ]Regular Expression must not be checked; Find, Replace Rest. Thanks to recursion which no other editor has been brave enough to provide and you failed to consider in your request, blank lines no matter how many will be removed.

    • hi.
      I'm using textFX happyly and without problems.
      anyway, I'd like to learn the regular expression to find end of lines in notepad++
      I tryed with every \n or \r possible combinations, I just can't do it..
      can you help me? I need to unwrap text but with more customizations.
      thank you

    • The Ctrl+R replace dialog was squeezed into the Notepad++ 3.4 release. All of the regular expressions are at the top of the dialog. Don't use \r or \n, the find & replace boxes are multi line so you put in returns, tabs, and pasted text just like an editor. Use Ctrl+M for RETURN and Ctrl+I for TAB.

      >I need to unwrap text but with more customizations

      Unwrap text in TextFX isn't good enough?

    • cyberman

      Hello, Chris Severance!!!

      Thank you for your info!!!

      Yes, it is working in the new Notepad++ 3.4 release.  In the Ctrl+R dialog, I can find with "Ctrl+M Ctrl+J Ctrl+M Ctrl+J" and replace with "Ctrl+M Ctrl+J".  All the empty lines are deleted.  Or you can even trim trailing spaces before the deleting.  To make sure that the empty lines with spaces get deleted.

    • It's not necessary to put in both ^M and ^J. The line endings are forced to the editor style before searching. This allows multiline text from history lists and from Load & Save to always function properly.