Menu

FAQ for newline search and replace

pshute
2006-09-20
2012-11-13
  • pshute

    pshute - 2006-09-20

    This is a repost of something I posted in the help forum.

    How to search for newlines and how to include them in the replace string seems to be a very commonly asked question in the help forum. There seem to be several ways to do it, involving both control+H and control+R find/replace options, regexp, no regexp, whether you want them in your search string or your replace string, etc.

    It would be nice if someone could create a newline find and replace FAQ for http://notepad-plus.sourceforge.net/uk/about.php. Even a basic one we could build on.

    If I wrote one myself, how would I get it posted on the site?  Who do I contact?

     
    • pshute

      pshute - 2006-10-03

      Below is a proposed FAQ for searching for and replacing newlines.  Could you please help by proof reading it and testing it.  Also add any notes you think might help, or methods I've missed. Hopefull the tabbing will be displayed, otherwise it's going to look like a mess.

      Notepad++ newline search and replace FAQ  - 3/10/06, test on v3.9 beta.

      Searching for, and replacing, newlines in Notepad++ results in a lot of help requests.  This is because there are 2 search and replace commands, each with 2 modes (regular expressions or no regular expression) and some bugs inherited from the Scintilla Project that Notepad++ is based on.  Some things that work in search strings don't work in replace strings, and vice versa.  Hopefully this FAQ will cover all the possible cases so that everyone's questions will be answered.

      1. The Search field:
          1.1 Simple search (control+H) without regexp
              You can turn on View/Show End of Line or view/Show All, and select the now visible newline characters. Then when you start the command some characters matching the newline character will be pasted into the search field.  Matches will be replaced by the replace string, unlike in regex mode.
              Note 1: If you select them with the mouse, start just before them and drag to the start of the next line. Dragging to the end of the line won't work.
              Note 2: You can't copy and paste them into the field yourself.
          1.2 Simple search (control+H) with Regexp
              The $ symbol will match newlines, but they won't be replaced by the replace string.  They only help locate the position of it - you can only use them at the end of the search string, because this command only searches within lines in this mode.
          1.3 Advanced search (control+R) without regexp
              Control+M will insert something that matches newlines. They will be replaced by the replace string.
          1.4 Advanced search (control+R) with Regexp
              Can't be done.
                 
      2. The Replace field:
          2.1 Simple search (control+H) without regexp
              Can't be done.
          2.2 Simple search (control+H) with Regexp
              The $ symbol will insert a newline.
          2.3 Advanced search (control+R) without regexp
              Control+M will replace the search text with a newline.
          2.4 Advanced search (control+R) with Regexp
              Oddly, control+M will replace the search text with a newline, but $ just replaces it with a $.

       
    • Nobody/Anonymous

      Look onto the side of Notepad++. Here you could find the developer of Notepad. Also you could find a contact address in Notepad, too. Look in help dialog.

      But your problem is a problem of scintilla and not a problem of Notepad++. Scintilla don't support newline tags in RegEx.

      If you find a solution or if you extend the scintilla with RegEx newline search and replace, you will help a lot of users.

       
    • Nobody/Anonymous

      Just either
      a) search this mailing list, the bug and RFE databases and collect possible workarounds. Then post it as HTML to Don Ho and ask him to extend the RegExp Help (maybe take the RegExp help as a basis, extend it and fix some typos ;)
      or
      b) extend the scintelle component to understand \n \t \r etc. and send them the patch. They will announce it properly on their site and the n++ developers will recognize and tell as well.

      So long, Georg

       
      • pshute

        pshute - 2006-09-28

        OK, I've found his email address.  Not sure when I'll get it done though (if ever).